-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.mjs
56 lines (43 loc) · 1.31 KB
/
app.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import express from 'express'
import mongoose from 'mongoose'
import dotenv from "dotenv"
import morgan from 'morgan'
import cors from 'cors'
import authRouter from './routes/auth.mjs'
import { menuRouter, foodRouter, ingredientRouter, nutritionRouter, stepRouter, recipeRouter} from './routes/routes.mjs'
import swagger from 'swagger-ui-express'
import yaml from 'js-yaml'
import fs from 'fs'
dotenv.config()
const swaggerDocs = fs.readFileSync('./docs/index.yml', 'utf8');
mongoose.connect(
process.env.DB_CONNECT ,
{
useUnifiedTopology: true,
useNewUrlParser: true,
},
()=>{
console.log('db is connected')
}
)
var app = express()
app.use(cors())
app.use( express.json() )
app.use(morgan('tiny'))
app.use('/user', authRouter )
app.use('/docs', swagger.serve, swagger.setup( yaml.safeLoad(swaggerDocs)));
app.get('/', (req, res ) => {
return res.json({
messsage: "Visit /docs for endpoint documentation."
})
})
app.use('/food', foodRouter )
app.use('/ingredients', ingredientRouter )
app.use('/recipe', recipeRouter )
app.use('/nutrition', nutritionRouter )
app.use('/menu', menuRouter )
app.use('/step', stepRouter )
app.use((req, res, next) => {
return res.status(404).send({ error: 'This Route '+req.url+' Not found.' });
});
app.listen(process.env.PORT || 8000)