backendstack21 / 0http Goto Github PK
View Code? Open in Web Editor NEWZero friction HTTP requests router. The need for speed!
Home Page: https://0http.21no.de
License: MIT License
Zero friction HTTP requests router. The need for speed!
Home Page: https://0http.21no.de
License: MIT License
File: /lib/utils/queryparams.js
Line 3: new URLSearchParams(search.replaceAll('[]=', '='))
The string function 'replaceAll' is only supported in Node >= 15.
This is a breaking change which is causing everything to collapse
Hey there again! I've been working on my side project that uses code from low
library, as well as outstanding issues in this project. However, I figured out that only resWrapper
class extends a Writeable Stream
. http.IncomingMessage
extends Readable Stream
, but reqWrapper
does not, which breaks a lot of middlewares, especially raw-body
and (by extension) body-parser
. This is partially fixable through ugly hacks or a rewrite of reqWrapper
(which would require a new major semver). However, I am curious to know, whether there are any specific reasons why low
library does not implement reqWrapper
as a Readabale Stream
?
Server crash when aborting wrk
when using fast-proxy
with 0http
with low
server
Ref: fastify/fast-proxy#35
I have the following code:
(Happens also without undici)
const { proxy } = fastProxy({
base: 'http://localhost:4000',
undiciOptions: {
connections: 4000,
pipelining: 20,
requestTimeout: 5000,
},
});
const { router, server } = cero({
server: low(),
});
router.all('/*', (req, res) => proxy(req, res, req.url, {}));
server.listen(3000, (socket) => {
if (socket) {
console.log('HTTP server ready!');
}
});
With an additional restana
server listening on port 4000
Then run
wrk -t8 -c50 -d20s http://localhost:3000/api/v1/test
hit CTRL-C to stop wrk
.
Result:
process abort on with the following error:
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
There was an uncaught exception. I'm now going to commit suicide; farewell all.
When I'm using 0http
without low
it doesn’t happen
The process should not abort if I stop wrk
Describe the bug
This expression is not callable.
error when using 0http.
To Reproduce
import cero from '0http';
const { router, server } = cero();
server.listen(3000);
Expected behavior
cero should be able to be called and the router
and server
should be able to be used.
Additional context
0http version: 3.5.1
typescript version: 5.0.4
IMHO there is no need to relay on the legacy querystring.parse method any longer, which is used in https://github.com/BackendStack21/0http/blob/master/lib/utils/queryparams.js .
Is there a chance to replace it with the native URLSearchParams?
Maybe this gives an additional performance boost?
E.g.
module.exports = (req, url) => {
const [path, search] = url.split('?')
const searchParams = new URLSearchParams(search.replace(/\[\]=/g, '='))
req.path = path
req.query = Object.fromEntries(searchParams)
}
First, I want to congratulate you on doing something so simple to use, but so fast.
Both natively and with expressjs (I think that competing against this framework does not hurt you) you can use pipe on the response object in the router, but can't when using low server.
const low = require('0http/lib/server/low')
const cero = require('0http')
const { router, server } = cero({
server: low()
})
router.get('/image.png', (req, res) => {
res.setHeader('Content-Type', 'image/png')
const { createReadStream } = require('fs')
const readStream = createReadStream('./test.png')
readStream.pipe(res)
})
server.listen(3000, (socket) => {
if (socket) {
console.log('HTTP server ready!')
}
})
Considerations:
To achieve that, the response object must be a Writable Stream.
Just asking if it's possible to use sessions (similar to express-session) in 0http?
Or if there is any known implementation of such
hello, can you explain example code how to use middleware like cors in 0http find-my-way router ?
i just found demos with sequential router,
thank you
how can I use this with typescript? or it only supports javascript as of now? An example would be very helpful if it supports typescript.
Can you get Express serve-static
to work with low
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.