-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (37 loc) · 1.19 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
46
47
48
49
require('dotenv').config();
const express = require('express')
const app = express();
const bodyParser = require('body-parser');
const cors = require("cors");
const logger = require('morgan')
const expressJwt = require('express-jwt');
const corsOptions = {
origin: "http://localhost:3000"
};
app.use(cors(corsOptions));
app.use(logger('dev'));
app.use(express.static(`${__dirname}/public`));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.json());
app.get("/", (req, res) => {
res.json({ message: "Welcome to zhichi." });
});
require('./helper/passport');
require('./routes/user')(app);
require('./routes/comment')(app);
require('./routes/ticket')(app);
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
const PORT = parseInt(process.env.PORT, 10) || 3000;
app.listen(PORT, (err) => {
if (err) {
console.error(`Error starting the app:${err}`)
}
console.info(`The server is running on localhost PORT: ${PORT}`);
});
module.exports = app;