-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (38 loc) · 977 Bytes
/
Copy pathapp.js
File metadata and controls
44 lines (38 loc) · 977 Bytes
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
import express from 'express'
import cors from 'cors'
import swaggerUI from 'swagger-ui-express'
import swaggerJSdoc from 'swagger-jsdoc'
import petRoutes from './pets/routes/pets.routes.js'
const app = express()
const port = 3000
//swagger def'n
const swaggerSpec = {
definition: {
openapi: '3.0.0',
info: {
title: 'Pets API',
version: '1.0.0',
},
servers: [
{
url: `http://localhost:${port}`,
}
]
},
apis: ['./pets/routes/*.js'],
}
// Global middlewares
app.use(cors())
app.use(express.json())
app.use(
'/api-docs',
swaggerUI.serve,
swaggerUI.setup(swaggerJSdoc(swaggerSpec))
)
//Routes
app.use('/pets', petRoutes);
//Server setup
if (process.env.NODE_ENV !== 'test') {
app.listen(port, () => console.log(`⚡️[server]: Server is running at https://localhost:${port}`));
}
export default app;