-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (30 loc) · 950 Bytes
/
index.js
File metadata and controls
41 lines (30 loc) · 950 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
const express = require('express'),
dotenv = require('dotenv'),
router = require('./router'),
cors = require('cors'),
bodyParser = require('body-parser'),
errorHandling = require('./middleware/errorHandling'),
swaggerUi = require("swagger-ui-express");
dotenv.config();
const PORT = process.env.PORT || 5000;
const app = express();
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors())
// Dokumentasi
const swaggerDocument = require('./docs/main.json');
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// ini router utama
app.use('/api/v1', router);
//middleware error handling
app.use(errorHandling)
// Handle 404 route
app.get('*', (req, res) => {
return res.status(404).json({
error: 'End point is not registered'
})
})
app.listen(PORT, () => {
console.log(`Server is running at PORT ${PORT}`);
});