-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (36 loc) · 1.05 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require("express");
const app = express();
const config = require("./config/index");
const apiRoute = require("./controllers/api.route")();
const morgan = require('morgan');
const path = require('path');
require("./db")
const port = process.env.PORT || 9090;
const bodyParser = require('body-parser')
const cors = require("cors");
app.use(express.static(path.join(__dirname, 'public')));
// Third party middlewares
app.use(morgan('dev'));
app.use('/image', express.static(path.join(__dirname, 'uploads')))
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(cors());
// Routes
app.use("/api", apiRoute);
// error handling Middleware
app.use(function (err, req, res, next) {
res.status(err.status || 400)
res.json({
errmsg: err.msg || err,
status: err.status || 400,
})
})
app.listen(port, (err, done) => {
if (err) {
console.log("Problem loading server")
}
else {
console.log(`Server listening at port ${port}`)
}
})