forked from HackFSU/hackfsu-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemoServer.js
More file actions
73 lines (54 loc) · 1.52 KB
/
demoServer.js
File metadata and controls
73 lines (54 loc) · 1.52 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
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Simple express app to mimic backend. For testing only.
*/
var http = require('http');
var express = require('express');
var morgan = require('morgan');
var path = require('path');
var app = express();
var port = 5000;
function boot() {
var server = http.createServer(app);
server.on('listening', function() {
console.log('Server Live @ http://localhost:' + port);
});
server.listen(port);
}
app.use(morgan('dev'));
app.use('/static', express.static(path.join(__dirname, './build/static')));
app.use('/static', express.static(path.join(__dirname, './static')));
/**
* Render static views
*/
function getStaticView(getPath, viewPath) {
app.get(getPath, function(req, res) {
res.sendFile(path.join(__dirname, './build/views/'+viewPath+'/index.html'));
});
}
var staticViews = [
{ getPath: '/', viewPath: 'index' },
{ getPath: '/register', viewPath: 'register' },
{ getPath: '/help', viewPath: 'help' },
{ getPath: '/user/login', viewPath: 'user/login' },
{ getPath: '/user/profile', viewPath: 'user/profile' },
{ getPath: '/error/404', viewPath: 'error/404' },
{ getPath: '/error/500', viewPath: 'error/500' }
];
staticViews.forEach(function(view) {
getStaticView(view.getPath, view.viewPath);
});
// Redirect shortcuts
app.get('/login', function(req, res) { res.redirect('/user/login'); });
/**
* Mock api
*/
/**
* Direct boot if run from node command
*/
if (require.main === module) {
boot();
}
module.exports = {
boot: boot,
app: app
};