/
mastercond
/
browser-slicer-3.7
Обзор
Документация
Войти
/
mastercond
/
browser-slicer-3.7
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sample/init.js
35 строк
1 KB
Stewart Allen
update module sample with worker code injection
13 ноя 2022, 19:16
13 ноя 2022, 19:16
ed6c771
Код
Авторство
О чём код?
// this is called from the `app.js` function `initModule()` around line `200` // from there you can get the structure passed in the "server" object // which includes and `api` and other helper functions module.exports = function(server) { server.util.log("--- sample server-side module installed ---"); // insert script after all others in kiri main code server.inject("kiri", "kiri.js", {end: true}); // insert script after all others in kiri worker code server.inject("kiri_work", "work.js", {end: true}); server.onload(() => { server.util.log("--- called after all modules loaded ---"); }); // adding URL endpoints on the server server.path.full({ // register the endpoint "/postit" "/postit": (req, res, next) => { let chunks = []; req.on('data', data => { chunks.push(data.toString()); }); req.on('end', () => { let data = chunks.join(''); server.util.log({server_received: data}); res.end(`received ${data.length} bytes`); }); } }); };