-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (43 loc) · 1.58 KB
/
server.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 app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const path = require('path');
const apiRoutes = require('./app/apiRoutes.js');
const compression = require('compression');
/* Require .env */
const dotenv = require('dotenv');
dotenv.config();
dotenv.load();
const port = process.env.PORT || 4000
app.use(compression());
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views/resetPassword"));
/* Connect to db */
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DB_URI, {useMongoClient: true})
if (process.env.NODE_ENV !== 'production') {
const webpackDevHelper = require('./index.dev.js')
const logger = require('morgan')
console.log('DEVELOPMENT ENVIRONMENT: Turning on WebPack Middleware...')
app.use(logger('dev'));
webpackDevHelper.useWebpackMiddleware(app)
} else {
console.log('PRODUCTION ENVIRONMENT..')
app.use('/js', express.static(__dirname + '/dist/js'))
}
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'assets')));
// app.use(express.static(path.join(__dirname, 'node_modules')));
app.use(express.static(path.join(__dirname, 'views')));
app.use('/api',apiRoutes);
/* Index route */
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'dist', 'index.html'))
})
/* Ignite server */
app.listen(port, () => {
console.log("Server running at http://localhost:" + port);
})