This repository was archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (72 loc) · 1.96 KB
/
index.js
File metadata and controls
81 lines (72 loc) · 1.96 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
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
const db = require("./pool");
const server = require("./server");
const Page = require("./classes/page");
const Nav = require("./classes/nav");
const PageResponse = require("./classes/page_response");
function pageRoutes() {
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return new PageResponse(true, "", []);
}
});
// Pages
server.route({
method: 'GET',
path: '/pages',
handler: async (request, h) => {
return await new Page().get.all();
}
});
server.route({
method: 'POST',
path: '/pages',
handler: async (request, h) => {
return await new Page().create(request.payload);
}
});
server.route({
method: 'PUT',
path: '/pages',
handler: async (request, h) => {
console.log(request.payload);
return await new Page().update(request.payload.slug, request.payload.page);
}
});
// Single Page
server.route({
method: 'GET',
path: '/pages/{page}',
handler: async (request, h) => {
return await new Page().get.bySlug.raw(request.params.page);
}
});
server.route({
method: 'GET',
path: '/pages/rendered/{page}',
handler: async (request, h) => {
return await new Page().get.bySlug.rendered(request.params.page, request.payload);
}
});
// Navs
server.route({
method: 'GET',
path: '/navs/{parent}',
handler: async (request, h) => {
return new Nav().get.byParent(request.params.parent);
}
});
}
async function main() {
// Initialize Routes:
pageRoutes();
// Wait for the server to start.
await server.start();
console.log('Server running on %s', server.info.uri);
}
main().then(() => {});
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});