example adding URL POST endpoint on the server and sending data to it
This commit is contained in:
parent
45d67f7783
commit
eb98c88d08
2 changed files with 23 additions and 0 deletions
|
|
@ -13,5 +13,20 @@ server.onload(() => {
|
||||||
server.util.log("--- called after all modules loaded ---");
|
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`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,12 @@ console.log('--- in the browser main loop ---');
|
||||||
// the kiri api starts around line `260` of `src/kiri/main.js`
|
// the kiri api starts around line `260` of `src/kiri/main.js`
|
||||||
kiri.load(function(api) {
|
kiri.load(function(api) {
|
||||||
console.log('--- kiri startup complete ---');
|
console.log('--- kiri startup complete ---');
|
||||||
|
|
||||||
|
// send data to our "/postit" endpoint
|
||||||
|
fetch("/postit", {
|
||||||
|
method: "POST",
|
||||||
|
body: "this is a test of the POST url endpoint"
|
||||||
|
}).then(res => res.text()).then(text => {
|
||||||
|
console.log({server_said: text});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue