forked from mozilla/webmaker-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
79 lines (69 loc) · 1.37 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
var Hapi = require('hapi');
var Path = require('path');
var qs = require('querystring');
var bsd = require('./src/util/bsd');
// Create server
var server = new Hapi.Server({
connections: {
router: { stripTrailingSlash: true },
routes: {
files: { relativeTo: Path.join(__dirname, 'build') }
}
}
});
server.connection({
port: process.env.PORT || 8000
});
// Route handlers
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.file('index.html');
}
});
server.route({
method: 'GET',
path: '/users/{user}/projects/{project}',
handler: function (request, reply) {
reply.redirect('webmaker://play?' + qs.stringify(request.params));
}
});
server.route({
method: 'GET',
path: '/favicon.ico',
handler: function (request, reply) {
reply.file('favicon.ico');
}
});
server.route({
method: 'POST',
path: '/signup',
handler: function (request, reply) {
bsd(request.payload.email, function (err, body) {
if (err) {
return reply({ok:false});
}
});
reply({ok:true});
}
});
server.route({
method: 'GET',
path: '/{path}/{param*}',
handler: {
directory: {
path: [
'css',
'favicons',
'fonts',
'img',
'js'
]
}
}
});
// Start listening
server.start(function () {
console.log('Server running at:', server.info.uri);
});