Git Product home page Git Product logo

baojs's People

Contributors

antongolub avatar iamacup avatar kylejreed avatar mattreid1 avatar serajhqi avatar yusfuu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

baojs's Issues

Allow for base url

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/

Creating a CI/CD Website and Documentation System for BaoJS

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!

Can't set status without also setting headers

  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: {},
    }
  );

Middleware usage

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

must write some unit tests

let's consider writing unit tests for baojs. we can discuss it under this issue. i would like to contribute btw.

Add a changelog and push git tags

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.

WebSockets error: TypeError: null is not an object (evaluating 'res.status')

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

Multiple middleware per route

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

Benchmarks: add Fastify

Comparing baojs to express is quite unfair since Fastify is the fastest framework.
Better compare to Fastify than Express.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.