-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (38 loc) · 1.07 KB
/
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
39
40
41
42
43
44
45
require('dotenv').config(); // .env variables
const express = require('express');
const cors = require('cors');
const PORT = process.env.PORT || 8080;
const db = require('./app/models');
const app = express();
const corsOptions = {
origin: 'https://ngnl666.github.io',
method: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
allowedHeaders: [
'Origin',
'Content-Type',
'Authorization',
'Accept',
'x-access-token',
],
};
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors(corsOptions));
// db
db.mongoose
.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('Connect db succeeded!'))
.catch((err) => {
console.log('Connect db failed!', err);
process.exit();
});
// routes
const note = require('./app/routes/note');
const publish = require('./app/routes/publish');
app.use('/api/note', note, (req, res, next) => next());
app.use('/api/publish', publish, (req, res, next) => next());
// server
app.listen(PORT, () => console.log('Server is running.'));