-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (47 loc) · 1.36 KB
/
index.js
File metadata and controls
53 lines (47 loc) · 1.36 KB
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
// Node Modules
const express = require('express')
const formidableMiddleware = require('express-formidable')
const swaggerJsDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')
const { PORT = 8002 } = process.env
// Custom Modules
const cars = require('./routers/cars')
const products = require('./routers/products')
// Init
const app = express()
app.use(formidableMiddleware())
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Binar Cars Express API with Swagger",
version: "0.1.0",
description:
"This is a simple CRUD API application made with Express and documented with Swagger",
license: {
name: "MIT",
url: "https://spdx.org/licenses/MIT.html",
},
contact: {
name: "LogRocket",
url: "https://logrocket.com",
email: "info@email.com",
},
},
servers: [
{
url: "http://localhost:8002/api/",
},
],
},
apis: [
"./routers/cars.js",
"./routers/products.js"
],
};
const specs = swaggerJsDoc(options);
// Routing
app.use('/api/cars', cars)
app.use('/api/products', products)
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
app.listen(PORT)