-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 935 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
const express = require('express');
const createError = require('http-errors');
const morgan = require('morgan');
require('dotenv').config();
const cors = require('cors');
const app = express();
app.use('/res/uploads', express.static('uploads'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan('dev'));
global.__basedir = __dirname;
var corsOptions = {
origin: "http://localhost:8080"
};
app.use(cors(corsOptions));
app.get('/', async (req, res, next) => {
res.send({ message: 'Awesome it works 🐻' });
});
app.use('/api', require('./routes/api.route'));
app.use((req, res, next) => {
next(createError.NotFound());
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
status: err.status || 500,
message: err.message,
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`🚀 @ http://localhost:${PORT}`));