forked from elliefarrer/festival-companion-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (30 loc) · 1.05 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
// Requires
const express = require('express');
const bodyParser = require('body-parser');
const router = require('./config/routes');
const errorHandler = require('./lib/error-handler');
const morgan = require('morgan');
//Environment
const { port, dbURI } = require('./config/environment');
//Mongoose/Mongo
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect(dbURI);
// Initialise app
const app = express();
//Static folder
app.use(express.static(`${__dirname}/public`));
//Middleware
app.use(morgan('dev'));
app.use(bodyParser.json()); // Allows other HTTP methods
// app.use((req, res, next) => {
// res.append('Access-Control-Allow-Origin', ['*']);
// res.append('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
// res.append('Access-Control-Allow-Header', 'Content-Type');
// next();
// });
//
app.use('/api', router); // Allows use of router
app.use(errorHandler);
app.listen(port, () => console.log(`Expess is listening to port ${port}`));
module.exports = app; // Exported to be used in tests