-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (49 loc) · 1.9 KB
/
server.js
File metadata and controls
61 lines (49 loc) · 1.9 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const path = require('path'),
express = require('express'),
app = express(),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
dotenv = require('dotenv'),
mongoose = require('mongoose')
require('dotenv').config();
dotenv.load();
var port = process.env.PORT || 4000;
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views/resetPassword"));
var apiRoutes = require('./app/apiRoutes');
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DATABASE_URL, {useMongoClient: true});
if (process.env.NODE_ENV !== 'production') {
const webpackDevHelper = require('./index.dev.js')
const logger = require('morgan')
console.log('DEVOLOPMENT 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());
// Setting up express to serve static files
app.use(express.static(path.join(__dirname, 'uploads/public')));
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')));
// we always want to serve the index.hbs
app.get('/', (req, res) => {
if (process.env.NODE_ENV !== 'production') {
res.sendFile(path.join(__dirname, 'assets/index.hbs'))
} else {
res.sendFile(path.join(__dirname, 'dist/index.hbs'))
}
})
// Routes for the Api
app.get('/api', function (req, res) {
res.send('Hello! The Api Server is listening at http://localhost:' + port + '/api/v1');
});
app.use('/api/v1', apiRoutes);
app.listen(port, function () {
console.log('Server running at http://localhost:' + port);
})