This repository was archived by the owner on Mar 10, 2026. 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
71 lines (60 loc) · 1.67 KB
/
index.js
File metadata and controls
71 lines (60 loc) · 1.67 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
const Hapi = require("@hapi/hapi");
const Joi = require("joi");
const baseMapHelpers = require("./helpers/baseMap.js");
const serverMethodCacheOptions = {
expiresIn: 7 * 24 * 60 * 60 * 1000,
cache: "memoryCache",
generateTimeout: 2 * 1000,
};
const server = Hapi.server({
port: process.env.PORT || 3000,
});
const routes = require("./routes/routes.js");
async function init() {
try {
server.cache.provision({
provider: {
constructor: require("@hapi/catbox-memory"),
options: {
partition: "memoryCache",
maxByteSize: process.env.MEMORY_CACHE_SIZE || 1000000000, // ~ 1GB
},
},
name: "memoryCache",
});
await server.register(require("@hapi/inert"));
server.validator(Joi);
server.route(routes);
server.method("getAllDocuments", baseMapHelpers.getAllDocuments, {
cache: serverMethodCacheOptions,
});
server.method("getDocument", baseMapHelpers.getDocument, {
cache: serverMethodCacheOptions,
});
server.method("getBasemap", baseMapHelpers.getBasemap, {
bind: {
server: server,
},
cache: serverMethodCacheOptions,
});
await server.start();
console.log("server running ", server.info.uri);
} catch (error) {
console.log(error);
}
}
async function gracefullyStop() {
console.log("stopping hapi server");
try {
await server.stop({ timeout: 10000 });
console.log("hapi server stopped");
} catch (err) {
console.log(err);
process.exit(1);
}
process.exit(0);
}
// listen on SIGINT and SIGTERM signal and gracefully stop the server
process.on("SIGINT", gracefullyStop);
process.on("SIGTERM", gracefullyStop);
init();