@gibme/webserver

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