-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
153 lines (139 loc) · 3.55 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
const moonboots = require('moonboots_hapi');
const moonbootsConfig = require('./moonbootsConfig');
var peopleAPI = require('./plugins/peopleAPI');
var pagesDataAPI = require('./plugins/pagesDataAPI');
var programsAPI = require('./plugins/programsAPI');
var factsAPI = require('./plugins/factsAPI');
var gameAPI = require('./plugins/gameAPI');
server.connection({ host: 'localhost', port: 3000 });
server.route([
{
method: 'GET',
path: '/api/me',
handler: function (request, reply) {
reply({
id: 10,
firstName: 'Ryan',
lastName: 'Baron',
email: '[email protected]',
coolnessFactor: 10
});
}
},
/*
{
method: 'GET',
path: '/api/pages/index',
handler: function (request, reply) {
reply({
id: 'index',
class: 'index-page page',
title: 'Index Page Title',
description: 'This is just a short description of the page for the header meta section',
body: '<p>This is just some temporary main content text wrapped in a p element for testing purposes</p>'
});
}
}
*/
]);
/*
server.register([
{
register: MoonBootsHapi.register,
options: moonbootsConfig
},
{
register: fakeApi.register
},
{
register: staticRoutes
}
]
*/
server.register([
{
register: moonboots.register,
options: moonbootsConfig
},
{
register: peopleAPI.register
},
{
register: programsAPI.register
},
{
register: pagesDataAPI.register
},
{
register: factsAPI.register
},
{
register: gameAPI.register
}
], function (err) {
if (err) throw err;
// If everything loaded correctly, start the server:
server.start(function (err) {
if (err) throw err;
console.log('Server running at-->', server.info.uri);
//console.log('Backyard Engineers is running at: http://' + config.http.listen + ':' + config.http.port);
});
});
//server.start(() => {
//console.log('Server running at:', server.info.uri);
//});
/*
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ host: 'localhost', port: 3000 });
//server.connection({ host: config.http.listen, port: config.http.port });
*/
/*
var Hapi = require('hapi');
var config = require('getconfig');
var MoonBootsHapi = require('moonboots_hapi');
var moonbootsConfig = require('./moonbootsConfig');
//var fakeApi = require('./fakeApi');
//var staticRoutes = require('./staticRoutes');
var internals = {};
var server = new Hapi.Server();
server.connection({ host: config.http.listen, port: config.http.port });
// set clientconfig cookie
internals.configStateConfig = {
encoding: 'none',
ttl: 1000 * 60 * 15,
isSecure: config.isSecure
};
server.state('config', internals.configStateConfig);
internals.clientConfig = JSON.stringify(config.client);
server.ext('onPreResponse', function(request, reply) {
if (!request.state.config) {
var response = request.response;
return reply(response.state('config', encodeURIComponent(internals.clientConfig)));
}
return reply.continue();
});
// require moonboots_hapi plugin
server.register([
{
register: MoonBootsHapi.register,
options: moonbootsConfig
},
{
register: fakeApi.register
},
{
register: staticRoutes
}
], function (err) {
if (err) throw err;
// If everything loaded correctly, start the server:
server.start(function (err) {
if (err) throw err;
console.log('Backyard Engineers is running at: http://' + config.http.listen + ':' + config.http.port);
});
});
*/