-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
95 lines (85 loc) · 2.03 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var Hapi = require('hapi');
var path = require('path');
const server = new Hapi.Server({
connections: {
routes: {
files: {
relativeTo: path.join(__dirname, 'dist')
}
}
}
});
server.connection({
host: 'localhost',
address: '0.0.0.0',
port: 3001
});
server.register(require('inert'), (err) => {
if (err) throw err;
/* Routes are handled from most-specific to least specific */
/* Favicon */
server.route({
method: 'GET',
path:'/favicon.ico',
handler: function (request, reply) {
var file = './favicon.ico';
console.log(file);
reply.file(file);
}
});
/* Serving images */
server.route({
method: 'GET',
path:'/img/{imageFile}',
handler: function (request, reply) {
var file = `./img/${request.params.imageFile}`;
console.log(file);
reply.file(file);
}
});
/* Serving css files */
server.route({
method: 'GET',
path:'/css/{cssFile}.css',
handler: function (request, reply) {
var file = `./css/${request.params.cssFile}.css`;
console.log(file);
reply.file(file);
}
});
/* Serving js source maps */
server.route({
method: 'GET',
path:'/js/{jsFile}.js.map',
handler: function (request, reply) {
var file = `./js/${request.params.jsFile}.js.map`;
console.log(file);
reply.file(file);
}
});
/* Serving static js files */
server.route({
method: 'GET',
path:'/js/{jsFile}.js',
handler: function (request, reply) {
var file = `./js/${request.params.jsFile}.js`;
console.log(file);
reply.file(file);
}
});
/* Catch-all route that will return our React SPA */
server.route({
method: 'GET',
path:'/{path*}',
handler: function (request, reply) {
var file = './index.html';
console.log(`${request.params.path || '/'}\n\t>> ${file}\n`);
reply.file(file);
}
});
/* Start the server */
server.start((err) => {
if (err) throw err;
console.log('Server running at:', server.info.uri);
});
});