forked from HubertHuckevoll/feedProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (43 loc) · 1.36 KB
/
app.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
46
47
48
49
50
51
52
// foreign modules
import * as http from 'http';
// Our own modules
import * as tools from './lb/tools.js';
import * as cntrl from './ct/controlC.js';
import * as payload from './lb/payload.js';
// Globals
const hostname = '0.0.0.0';
const port = (process.argv[2] !== undefined) ? process.argv[2] : 8080;
async function init()
{
globalThis.prefs = await tools.loadPrefs();
console.log('/* feedProxy */');
console.log('Local IP:', tools.getLocalIP()+':'+port);
console.log('Verbose logging:', (globalThis.prefs.verboseLogging === true) ? 'on' : 'off');
console.log('Cobbled together by MeyerK 2022/10ff.');
console.log('Running, waiting for requests.');
console.log();
tools.cLog('PREFS loaded:', globalThis.prefs);
}
async function router(request, response)
{
let pl = null;
let wasProcessed = false;
try
{
pl = await payload.getPayload(request, response);
}
catch (e)
{
console.log('ERROR fetching request', e);
wasProcessed = cntrl.emptyC(request, response);
console.log('');
console.log('');
return;
}
wasProcessed = await cntrl.run(request, response, pl);
console.log('DONE with request', pl.url, 'exit state was:', wasProcessed);
console.log('');
console.log('');
}
const server = http.createServer(router.bind(globalThis));
server.listen(port, hostname, init.bind(globalThis));