forked from magda-io/magda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (62 loc) · 1.98 KB
/
index.ts
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
import express from "express";
import * as yargs from "yargs";
import createApiRouter from "./createApiRouter";
import addJwtSecretFromEnvVar from "magda-typescript-common/src/session/addJwtSecretFromEnvVar";
const argv = addJwtSecretFromEnvVar(
yargs
.config()
.help()
.option("listenPort", {
describe: "The TCP/IP port on which the search-api should listen.",
type: "number",
default: 6122
})
.option("elasticSearchUrl", {
describe: "The url of the elasticsearch node to connect to",
type: "string",
default: "http://localhost:9200"
})
.option("jwtSecret", {
describe: "The shared secret for intra-network communication",
type: "string"
})
.option("datasetsIndexId", {
describe: "The id of the datasets index in elasticsearch",
type: "string",
demand: true,
default: "datasets45"
})
.option("regionsIndexId", {
describe: "The id of the regions index id",
type: "string",
demand: true,
default: "regions24"
})
.option("publishersIndexId", {
describe: "The id of the publishers index id",
type: "string",
demand: true,
default: "publishers4"
}).argv
);
// Create a new Express application.
const app = express();
app.use(
"/v0",
createApiRouter({
jwtSecret: argv.jwtSecret,
elasticSearchUrl: argv.elasticSearchUrl,
datasetsIndexId: argv.datasetsIndexId,
regionsIndexId: argv.regionsIndexId,
publishersIndexId: argv.publishersIndexId
})
);
app.listen(argv.listenPort);
console.log("Search API started on port " + argv.listenPort);
process.on(
"unhandledRejection",
(reason: {} | null | undefined, promise: any) => {
console.error("Unhandled rejection:");
console.error(reason);
}
);