Mercurial
view benchmark/bun-http-framework-benchmark/src/node/uws.js @ 268:f7b1188d5fb1
support repo rules Copilot bundle path
Match both +_repo_rules2+ and +http_archive+ Copilot CLI repository layouts during deployment and production startup.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 07 Aug 2026 13:02:41 -0700 |
| parents | a8976a008a9d |
| children |
line wrap: on
line source
/* Non-SSL is simply App() */ const uWS = require('uWebSockets.js') uWS.App() .get( '/', new uWS.DeclarativeResponse() .writeHeader('content-type', 'text/plain') .end('Hi') ) .get( '/id/:id', new uWS.DeclarativeResponse() .writeHeader('content-type', 'text/plain') .writeHeader('x-powered-by', 'benchmark') .writeParameterValue('id') .write(' ') .writeQueryValue('name') .end() ) .post('/json', (res, req) => { readJson( res, (obj) => { res.writeHeader('content-type', 'application/json').end( JSON.stringify(obj) ) }, () => { res.end('Ok') } ) }) .listen(3000, (listenSocket) => { if (listenSocket) { console.log('Listening to port 3000') } }) function readJson(res, cb, err) { let buffer res.onData((ab, isLast) => { let chunk = Buffer.from(ab) if (isLast) { if (buffer) { cb(JSON.parse(Buffer.concat([buffer, chunk]))) } else { cb(JSON.parse(chunk)) } } else { if (buffer) { buffer = Buffer.concat([buffer, chunk]) } else { buffer = Buffer.concat([chunk]) } } }) res.onAborted(err) }