uws-helpers

1.0.0 • Public • Published

uws-helpers

uws-helpers is a library with helper functions for uWebSockets.js.

Typical usage

const { App } = require('uWebSockets.js');

const { getHeaderAuth, jsonResponse } = require('uws-helpers');

const app = App();

const accounts = new Set(['test1', 'test2']);

app.post('/my/api/endpoint', (res, req) => {
    const auth = getHeaderAuth(req);
    if (accounts.has(auth[1])) {
      return jsonResponse(res, '200', JSON.stringify( { msg: 'Welcome' } ));
    } else {
      return jsonResponse(res, '500', JSON.stringify( { error: 'Not authorized' } ));
    }
  );
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    2

Package Sidebar

Install

npm i uws-helpers

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

4.5 kB

Total Files

6

Last publish

Collaborators

  • guyo13