Nearly Perfect Mediocracy

    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' } ));
        }
      );
    });

    Keywords

    none

    Install

    npm i uws-helpers

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.5 kB

    Total Files

    6

    Last publish

    Collaborators

    • guyo13