mattreid1 / baojs Goto Github PK
View Code? Open in Web Editor NEW⚡️ A fast, minimalist web framework for the Bun JavaScript runtime
License: MIT License
⚡️ A fast, minimalist web framework for the Bun JavaScript runtime
License: MIT License
Hi @mattreid1,
Do you want to include baojs
in https://github.com/the-benchmarker/web-frameworks ?
It is a simple benchmarking project that has recently include bun
.
Then you can monitor how faster is baojs
comparing to express
.
Regards,
PS : I try to publish new result each monday (except the 24th of July)
I'd love to ability to set a base url. If you have a url like:
example.com/api/*
It would be great if you could set the base url to be /api/
I'm working on another bun project and I found that you can get more contributors with a website. I built a really simple website and documentation generation tool if you want to add it to your project. It's under the MIT License- I'm just sending it around the bun community so it gains some more traction. If you want to check it out, it's right here. It's all integrated with Github Actions so all you have to do is add the code to GitHub actions and then you're all set. If you don't want to, just let me know and close this issue- good luck with your project!
return ctx.sendJson(
{ someData: "someValue" },
{
status: 400,
}
);
Errors:
104 | * @param json The JSON to be sent in the response
105 | * @param options (optional) The Response object options
106 | * @returns The Context object with plain JSON
107 | */
108 | sendJson = (json, options = { headers: {} }) => {
109 | options.headers["Content-Type"] = "application/json";
^
TypeError: undefined is not an object (evaluating 'options.headers["Content-Type"] = "application/json"')
you have to do:
return ctx.sendJson(
{ someData: "someValue" },
{
status: 400,
headers: {},
}
);
How do you handle CORS requests?
CORS requests come from the browser through OPTIONS methods. It seems their handling is missing from bao.ts
. Should I make a PR to add this?
Nice work 👌.
Is supporting https://wintercg.org/ something Bao.js is interested in?
(CC @cyco130 author of HatTip which is a cross-platform Express.js alternative with preliminary Bun support.)
This section of your README points to non existing page that is supposed to support the 2.5x claim:
Bun was released as a fast, modern JavaScript runtime. One of the many improvements over Node.js was the 2.5x increase in HTTP request throughput when compared to the Node.js http module (reference).
In a middleware, is there a way to get the size of the response ctx.res
sent to the client?
Maybe a function like Context.redirect(newUrl)
to redirect the user to a different page could be added. I think it could be very usefull for many projects.
Exciting new project you have here. I'm experimenting with bun.sh atm and are trying to use baojs to replace express with bao. I have some dependencies in my node_modules ie ui5-tooling that runs an express server.
I'm trying to run some express middlewares through bao and have hacked the ui5 cli a bit to use bao instead. I understand that bao doesn't use app.use, but I need to specify a specific mountpath for my middleware. Is this something that is currently supported?
The issue is here
let's consider writing unit tests for baojs. we can discuss it under this issue. i would like to contribute btw.
I'm new to the Bun ecosystem (as of ~an hour ago) and decided to use Bao for my first exploration.
What would it take to get hot reloading going? https://bun.sh/docs/runtime/hot
I noticed there's no changelog and no git tags. This makes it really hard to know what changed between versions, and if there are breaking changes. Since I have a package that can be used as a middleware, it makes it harder for me to see if I need to make changes to it when updates release.
I would suggest creating a changelog using the Keep a Changelog format. This is what I am using for my own package. Also, by pushing the git tags, it would make it easier to compare the commits between versions.
Do we have such a thing?
WebSockets always throw errors when attempting to connect:
129 | message: (ws, msg) => router.handleWebSocket(ws).message(msg),
130 | },
131 | async fetch(req, server) {
132 | let ctx = new Context(req, server);
133 | const res = await router.handle(ctx);
134 | return res.status === 404 ? notFoundHandler(ctx) : res;
^
TypeError: null is not an object (evaluating 'res.status')
at node_modules/baojs/dist/bao.js:134:24
All I've done here is setup a simple websocket connection:
app.ws("/ws/room", {
close(ws) {
},
message(ws, msg) {
},
open(ws) {
},
});
It looks like the route handler doesn't create any Response object, but the fetch()
method expects one to always be present.
Bao version: 0.2.1
Bun verions: 1.0.18
For some APIs, its nice to have the ability to run some pre/post operations on a per-route or per-group basis. For example, you want some public routes, and some protected routes requiring a JWT token. Maybe this can currently be achieved in the Bao.before()
, but the DX around it could be improved.
One solution is to allow things like Bao.get()
to accept multiple IHandler
's.
get(...handlers: IHandler[]) {}
Another step up from that would be to implement a multi-router support like Express or Koa does
const app = new Bao();
const HelloRouter = new Router('/hello');
HelloRouter.before(logger());
HelloRouter.get(protect(), ctx => ctx.sendText('world'));
app.use(HelloRouter); // or app.use('/hello', HelloRouter) if preferred DX
Started a new project and created index.ts
with this inside:
import Bao from "baojs";
const app = new Bao();
But the new Bao()
is underlined with the following error:
This expression is not constructable.
Type 'typeof import("/path/to/project/node_modules/baojs/dist/index")' has no construct signatures.
I'm using version 0.2.1.
Comparing baojs to express is quite unfair since Fastify is the fastest framework.
Better compare to Fastify than Express.
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.