-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (27 loc) · 1.01 KB
/
Copy pathserver.js
File metadata and controls
35 lines (27 loc) · 1.01 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
#!/usr/bin/env node
'use strict';
const Hapi = require('hapi');
const filepaths = require('filepaths');
const hapiBoomDecorators = require('hapi-boom-decorators');
const config = require('./config');
async function createServer() {
// Инициализируем сервер
const server = await new Hapi.Server(config.server);
await server.register([
hapiBoomDecorators
]);
// Загружаем все руты из папки ./src/routes/
let routes = filepaths.getSync(__dirname + '/src/routes/');
for(let route of routes)
server.route( require(route) );
// Запускаем сервер
try {
await server.start();
console.log(`Server running at: ${server.info.uri}`);
} catch(err) { // если не смогли стартовать, выводим ошибку
console.log(JSON.stringify(err));
}
// Функция должна возвращать созданый сервер, зачем оно нужно, расскажу далее
return server;
}
createServer();