-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (29 loc) · 1010 Bytes
/
Copy pathindex.js
File metadata and controls
38 lines (29 loc) · 1010 Bytes
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
const express = require('express');
const dbConnect = require('./config/db');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const profile = require('./routes/profile');
const port = process.env.PORT || 5000;
dbConnect();
mongoose.connection.on('connected', () => {
console.log('Connected to MongoDB');
});
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.get('/', (req, res)=>{
res.send('Hello World!');
})
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
if (req.method === 'OPTIONS') {
res.header("Access-Control-Allow-Methods", "PUT, POST, DELETE, GET");
return res.status(200).json({});
}
next();
});
app.use('/api/profile', profile);
app.listen(port, ()=>{
console.log(`App is running at http://localhost:${port}`);
})