-
Notifications
You must be signed in to change notification settings - Fork 35
/
server.js
36 lines (27 loc) · 930 Bytes
/
server.js
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
const fts = require('fts');
const ftsHttp = require('fts-http');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const createEndpoint = async (path, type = 'get') => {
const tsFilePath = `./src/${path}.ts`;
const jsFilePath = `./build/${path}.js`;
const definition = await fts.generateDefinition(tsFilePath);
const handler = ftsHttp.createHttpHandler(definition, jsFilePath);
app[type](`/${path}`, handler);
console.log(`Registered /${path} handler`);
};
async function createServer() {
app.listen(port, () => {
console.log(`OG IMPACT server listening at http://localhost:${port}`);
});
console.log('Registering endpoints...');
await createEndpoint('image');
await createEndpoint('preview');
await createEndpoint('publish', 'post');
await createEndpoint('url');
}
createServer().catch((err) => {
console.error(err);
process.exit(1);
});