-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
136 lines (124 loc) · 2.84 KB
/
index.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const fs = require('fs');
const hapi = require('hapi');
const server = new hapi.Server();
// Insecure server
server.connection({
labels: 'insecure',
host: 'insecure.example.dev',
address: 'localhost',
port: 3000
});
// Another insecure server, different domain
server.connection({
labels: 'alsoinsecure',
host: 'alsoinsecure.example.dev',
address: 'localhost',
port: 3001
});
// Another insecure server, different domain, CORS enabled
server.connection({
labels: 'insecurecors',
routes: {
cors: {
origin: ["*"],
additionalHeaders: ["Accept-language"]
}
},
host: 'insecurecors.example.dev',
address: 'localhost',
port: 3002
});
// Secure server, no CORS
server.connection({
labels: 'secure',
tls: {
key: fs.readFileSync('./secure.example.dev.key'),
cert: fs.readFileSync('./secure.example.dev.crt')
},
host: 'secure.example.dev',
address: 'localhost',
port: 3005
});
// Another secure server, different domain
server.connection({
labels: 'alsosecure',
tls: {
key: fs.readFileSync('./alsosecure.example.dev.key'),
cert: fs.readFileSync('./alsosecure.example.dev.crt')
},
host: 'alsosecure.example.dev',
address: 'localhost',
port: 3006
});
// Another secure server, different domain, CORS enabled
server.connection({
labels: 'securecors',
tls: {
key: fs.readFileSync('./securecors.example.dev.key'),
cert: fs.readFileSync('./securecors.example.dev.crt')
},
routes: {
cors: {
origin: ["*"],
additionalHeaders: ["Accept-language"]
}
},
host: 'securecors.example.dev',
address: 'localhost',
port: 3007
});
// Add handlebars++. Not really necessary, but part of my typical boilerplate...
server.register([require('vision')], (err) => {
if (err) {
console.error('Failed to load a plugin: ', err);
}
server.views({
engines: {
hbs: require('handlebars')
},
relativeTo: __dirname,
path: './views',
isCached: false,
partialsPath: './views/partials',
helpersPath: './views/helpers',
layoutPath: './views/layouts',
layout: 'layout',
compileMode: 'sync'
});
});
// Plugin for statics
server.register([require('inert')], (err) => {
if (err) {
console.error('Failed to load a plugin: ', err);
}
});
// Routes hard coded here for now...
server.route([
{
method: 'GET',
path: '/',
handler: require('./handlers/ajax')
},
{
method: 'GET',
path: '/api/something',
handler: (request, reply) => {
reply('Yay! Got response from API @ ' + request.info.host);
}
},
{
method: 'GET',
path: '/css/stylesheet.css',
handler: function (request, reply) {
reply.file('./static/css/stylesheet.css');
}
}
]);
server.start((err) => {
if (err) {
throw err;
}
server.connections.map(obj => {
console.log('Server running at', obj.info.uri);
});
});