forked from galacticcouncil/HydraDX-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.mjs
More file actions
32 lines (25 loc) · 805 Bytes
/
server.mjs
File metadata and controls
32 lines (25 loc) · 805 Bytes
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
import Fastify from "fastify";
import appService from "./app.mjs";
import { IS_DOCKER_RUN, IS_GOOGLE_CLOUD_RUN } from "./variables.mjs";
function build() {
const fastify = Fastify({ trustProxy: true });
// Register your application as a normal plugin.
fastify.register(appService);
return fastify;
}
async function start() {
// You must listen on the port Cloud Run provides
const port = process.env.PORT || 3000;
// You must listen on all IPV4 addresses in Cloud Run
const host = IS_DOCKER_RUN || IS_GOOGLE_CLOUD_RUN ? "0.0.0.0" : "127.0.0.1";
try {
const server = build();
const address = await server.listen({ port, host });
console.log(`Listening on ${address}`);
} catch (err) {
console.error(err);
process.exit(1);
}
}
export default build;
start();