-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.14 KB
/
index.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
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const express = require('express');
const logger = require('morgan');
const PF_VERSION = require('./node_modules/@polyflow/sdk/package.json').version;
const app = express();
const port = 5555
const API_KEY_ID = `"API_KEY"`;
const BUILD = fs.readFileSync(__dirname + "/dist/polyflow-bundle.js", "utf-8");
app.use(logger('common', {
stream: fs.createWriteStream('./access.log', { flags: 'a' })
}));
app.use(logger('common'));
app.get('/', async (req, res) => {
res.send({
sdk: PF_VERSION
});
});
app.get('/generate', async (req,res) => {
const api = req.query.api;
const logEnabled = req.query.logEnabled ?? false;
const stagingEnabled = req.query.stagingEnabled ?? false;
if (!api) {
res.status(400);
res.send("Missing API key!");
return;
}
res.setHeader("Content-Type", "application/javascript");
res.send(
BUILD.replace(
API_KEY_ID,
`"${api}", { logEnabled: ${logEnabled}, stagingModeEnabled: ${stagingEnabled} }`
)
);
});
app.listen(port, () => {
console.log(`Polyflow SDK builder listening at ${port}`);
});