Polka: Replace native Http with UWS

Created on 22 Jan 2018  路  3Comments  路  Source: lukeed/polka

For better performance, consider replacing native Http with uws Http https://github.com/uNetworking/uWebSockets

Most helpful comment

@paulocoghi Think you deleted your comment, but I still got the email 馃槈

Yes you can still use middleware with uws http. Polka handles all routing & middleware; it only relies on http (or http replacement) to operate the request & response cycle.

Note that since this issue as closed, it's now possible to do this:

const polka = require('polka')
const { http } = require('uws');

let server = http.createServer(); // custom server

polka({ server }) // use SERVER directly
  .use(middlware1, middleware2)
  .get(...)
  .listen(3000)

All 3 comments

Hey~! This is actually an optimization to make on the user-side, since no everyone can/will want to use UWS, unfortunately.

It's really easy to do actually, and works since the built-in http server isn't called unless you call start|listen on Polka directly. This means that you can create the uws server & pass in Polka's handler.

There's a full example coming to the repo soon~

const polka = require('polka');
const { http } = require('uws');

const { handler } = polka().use(...).get(...);

http.createServer(app.handler).listen(3000);

It's _a lot_ like the HTTPS example, which also passes the Polka handler into a custom server.

Closing because a UWS example is already on my todo list, and that's all Polka can support.

Hope that helps, thanks~!

@paulocoghi Think you deleted your comment, but I still got the email 馃槈

Yes you can still use middleware with uws http. Polka handles all routing & middleware; it only relies on http (or http replacement) to operate the request & response cycle.

Note that since this issue as closed, it's now possible to do this:

const polka = require('polka')
const { http } = require('uws');

let server = http.createServer(); // custom server

polka({ server }) // use SERVER directly
  .use(middlware1, middleware2)
  .get(...)
  .listen(3000)

Thanks a lot, @lukeed :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dasantonym picture dasantonym  路  4Comments

alekbarszczewski picture alekbarszczewski  路  3Comments

flawyte picture flawyte  路  7Comments

itaditya picture itaditya  路  3Comments

lagmanzaza picture lagmanzaza  路  4Comments