-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (40 loc) · 1.38 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
const express = require('express');
const bodyParser = require('body-parser');
let jwt = require('jsonwebtoken');
let config = require('./config/keys');
let middleware = require('./middleware');
const courses = require("./routes/api/users");
const mongoose = require("mongoose");
const pino = require('pino');
const expressPino = require('express-pino-logger');
const logger = pino({ level: process.env.LOG_LEVEL || 'info' });
const expressLogger = expressPino({ logger });
function main () {
let app = express();
const port = process.env.PORT || 3000;
var cors=require('cors');
app.use(expressLogger);
app.options('*', cors());
app.use(bodyParser.urlencoded({ // Middleware
extended: true
}));
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use("/api/users", courses);
const db = require("./config/keys").mongoURI;
// Connect to MongoDB
mongoose
.connect(
db,
{ useNewUrlParser: true }
)
.then(() => console.log("MongoDB successfully connected for USERS SERVICE"))
.catch(err => console.log(err));
console.log(db);
// app.get('/api/management/courses', middleware.checkToken, handlers.index);
app.listen(port, () => console.log(`Server is listening on port: ${port}`));
}
main();