-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (43 loc) · 1.42 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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const musedbLink = require('./constants');
// const bodyParser = require("body-parser");
const animeRoute = require('./routes/anime');
const episodeRoute = require('./routes/episode');
const authRoutes = require("./routes/auth");
const app = express();
const port = process.env.PORT || 8080;
app.use(express.json());
// this is for CORS error
// app.use((req, res, next) => {
// res.setHeader("Access-Control-Allow-Origin", "*");
// res.setHeader("Access-Control-Allow-Methods", "*");
// res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
// });
app.use(cors());
app.use('/anime', animeRoute);
app.use('/episode', episodeRoute);
app.use("/auth", authRoutes);
app.use('/', (req,res,next)=>{
res.json({message: 'Muse Asia Server'});
})
app.use((error, req, res, next) => {
console.log(error);
const status = error.statusCode || 500;
const message = error.message;
const data = error.data;
res.status(status).json({ statusCode: status, message: message, data: data });
});
mongoose.connect(
process.env.Mongoose || musedbLink,
{
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
}
).then((result) => {
app.listen(port, ()=>{
console.log(`Server started at port ${port}!!`);
});
}).catch((err) => console.log(err));