forked from dez02/Travel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (28 loc) · 1.07 KB
/
index.js
File metadata and controls
35 lines (28 loc) · 1.07 KB
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
const express = require('express');
const app = express();
const apiRouter = require('./server/app/routes');
const mongoose = require('mongoose');
const morgan = require('morgan');
const port = process.env.PORT || 8080; // Define server PORT
// Link To Database
// mLab database
mongoose.connect('mongodb://admin:simplonco@ds129720.mlab.com:29720/travel');
// Local database just for dev
// mongoose.connect('mongodb://localhost:27017/test2');
// tell the app to look for static files in these directories
app.use(express.static('./server/static/'));
app.use(express.static('./client/dist/'));
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();
});
// Log all requests to the console
app.use(morgan('dev'));
// API ROUTER
app.use('/api', apiRouter);
// start the server
app.listen(port, err => {
console.log('Server is running on http://localhost:8080 or http://127.0.0.1:8080');
});