-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
75 lines (62 loc) · 1.19 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
'use strict';
const Hapi=require('hapi');
const port = +process.env.PORT || 5000;
const host = "0.0.0.0";
const knex = require("knex");
// Create a server with a host and port
const server = Hapi.server({
host,
port,
});
// Start the server
const start = async function() {
try {
await server.register(require('inert'));
// Add the index route
server.route({
method:'GET',
path:'/',
handler: (request,h) => {
return h.file('./index.html');
}
});
// Add the accounts getter
server.route({
method:'GET',
path:'/accounts',
handler: (request,h) => {
var pg = knex({
client: "pg",
connection: process.env.DATABASE_URL,
});
return pg("accounts").then(results => {
return results;
});
}
});
// Add the favicon route
server.route({
method:'GET',
path:'/favicon.ico',
handler: (request,h) => {
return h.file('./public/favicon.ico');
}
});
server.route({
method: 'GET',
path: '/public/{param*}',
handler: {
directory: {
path: './public'
}
}
});
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log('Server running at:', server.info.uri);
};
start();