forked from hngi/TEAM-FALCON-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 980 Bytes
/
index.js
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
require('express-async-errors')
const express = require('express');
const cors = require('cors');
const app = express();
const morgan = require("morgan")
const path = require("path")
const port = process.env.PORT;
const fileRoutes = require("./routes/files")
const errorMiddleware = require("./middleware/error")
const initDB = require("./config/db")
app.use(cors())
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use('/uploads', express.static(path.join(__dirname, './uploads/')));
//Api routes
app.use('/api/v1/files', fileRoutes);
//Handle invalid api endpoints
app.use((req, res, next) => {
throw new CustomError("Invalid request", 400);
});
// Handle server erros
app.use(errorMiddleware);
// Listen to port
app.listen(port, () => {
console.log(`::: Server listening on port ${port}`);
initDB()
});
app.on('error', (error) => {
console.log("::> An error occiurred in our server " + error);
});