-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
63 lines (54 loc) · 2.26 KB
/
server.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
import fastify from "fastify";
import fastifySwagger from "fastify-swagger";
import { version } from "./package.json";
import ChannelsAPI from "./src/api/channels";
import RedirectPlugin, { RedirectPluginOptions } from "./src/api/redirect";
import db from "./src/db/dynamodb";
import { MRSSAutoSchedulerAPI, MRSSAutoScheduler } from "./src/auto_scheduler/mrss";
import { PlaylistAutoSchedulerAPI, PlaylistAutoScheduler } from "./src/auto_scheduler/playlist";
const dbUrl = process.env.DB || "dynamodb://localhost:5000/eu-north-1";
const dbTablePrefix = process.env.DB_TABLE_PREFIX || "local";
const start = async() => {
const server = fastify({ ignoreTrailingSlash: true });
server.get('/', async () => {
return 'OK\n';
});
await server.register(fastifySwagger, {
routePrefix: "/api/docs",
swagger: {
info: {
title: "Eyevinn Schedule Service API",
version: version,
}
},
exposeRoute: true,
});
await server.register(db, {
uri: dbUrl,
channelsTableName: dbTablePrefix + "_channels",
schedulesTableName: dbTablePrefix + "_schedules",
mrssFeedsTableName: dbTablePrefix + "_mrssFeeds",
playlistsTableName: dbTablePrefix + "_playlists",
});
await server.register(ChannelsAPI, { prefix: "/api/v1" });
await server.register(MRSSAutoSchedulerAPI, { prefix: "/api/v1/auto" });
await server.register(PlaylistAutoSchedulerAPI, { prefix: "/api/v1/auto" });
const redirectOptions: RedirectPluginOptions = {
source: "/api/v1/mrss", destination: "/api/v1/auto/mrss"
}
await server.register(RedirectPlugin, redirectOptions);
const mrssAutoScheduler = new MRSSAutoScheduler(server.db.mrssFeeds, server.db.scheduleEvents, server.db.channels);
await mrssAutoScheduler.bootstrap(process.env.DEMO_TENANT || "demo");
await mrssAutoScheduler.run();
const playlistAutoScheduler = new PlaylistAutoScheduler(server.db.playlists, server.db.scheduleEvents, server.db.channels)
await playlistAutoScheduler.bootstrap(process.env.DEMO_TENANT || "demo");
await playlistAutoScheduler.run();
server.listen(process.env.PORT || 8080, process.env.IF || "127.0.0.1", (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server listening at ${address}`);
});
};
start();