-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (48 loc) · 1.59 KB
/
server.js
File metadata and controls
58 lines (48 loc) · 1.59 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
var path = require('path');
var https = require('https');
var express = require('express');
var webpack = require('webpack');
var bodyParser = require('body-parser');
var fs = require('fs');
var config = require('./config/webpack.prod');
var authenticate = require('./routes/authenticate');
var rest = require('./routes/VstsRest');
var DEBUG = require('./debug');
var app = express();
var compiler = webpack(config);
var port = process.env.PORT || 3000;
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
// Routes
app.use('/authenticate', authenticate);
app.use('/rest', rest)
app.use('/js', express.static(__dirname + '/js'));
app.use('/css', express.static(__dirname + '/css'));
app.use('/images', express.static(__dirname + '/images'));
app.get('*', function(req,res){res.sendFile(__dirname+'/index.html');});
if(DEBUG == true){
const options = {
key: fs.readFileSync('secrets/key.pem'),
cert: fs.readFileSync('secrets/cert.pem')
};
https.createServer(options, app).listen(port, function() {
console.log('Listening at https://localhost:' + port);
});
}
else{
console.log("WARNING: you are not running in debug mode. nothing will work!");
app.listen(port, "localhost", function(err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:' + port);
});
}