@gibme/webserver
TypeScript icon, indicating that this package has built-in type declarations

2.2.2 • Public • Published

Simple Express.js Application Wrapper

This wrapper makes it very easy to construct a new instance of an Express.js web server application using HTTP or HTTPs.

Features include:

  • Preloaded recommended headers (optional)
  • Automatic 404 handling (optional)
  • Compression (optional)
  • Auto-parsing of request bodies
  • WebSocket via additional method signature of .ws('path', (socket, request) => void)
  • Auto-generation of development SSL certificates for the hostnames supplied and installing a development root CA into the host OS.
    • Note: This mode is NOT for production use
  • Simple cloudflared support to spin up test tunnels using Cloudflare
    • Note: The public URLs will be randomly generated by Cloudflare

Documentation

https://gibme-npm.github.io/webserver/

Sample Code

import WebServer, { Logger } from '@gibme/webserver';

(async() => {
    const app = WebServer.create({
        autoStartTunnel: true
    });
    
    app.get('/', (request, response) => {
        return response.json({ success: true });
    })

    app.ws('/wss', (socket) => {
        socket.on('message', msg => {
            // simply echo the message back
            socket.send(msg);
        });
    });
    
    await app.start();
    
    Logger.info('Listening on: %s', app.localUrl);
    Logger.info('Listening on: %s', app.tunnelUrl);
    Logger.info('Listening on: %s', app.url);
})();

Readme

Keywords

none

Package Sidebar

Install

npm i @gibme/webserver

Weekly Downloads

1

Version

2.2.2

License

MIT

Unpacked Size

58.7 kB

Total Files

15

Last publish

Collaborators

  • brandonlehmann