🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

koa-simple-web

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-simple-web

A simple web server using Koa

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

koa-simple-web

A simple web server using Koa

Usage

$ npm install koa-simple-web

Simple HTTP

const web = new SimpleWeb({ port: 8080 });

web.route(new (require("koa-router"))());
web.use(async (ctx) => {});

await web.start();
await web.stop();

Something else

Koa's listen (which SimpleWeb uses) is itself sugar for

const http = require("http");
const Koa = require("koa");
const app = new Koa();
http.createServer(app.callback()).listen(3000);

Consequently, if you want to configure the underlying server instance (for example to use HTTPS), you can pass in a Node http.Server or https.Server to the constructor and that server will be used instead of a default HTTP configuration.

const fs = require('fs');
const https = require('https');

const options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

const server = https.createServer(options);

const web = new SimpleWeb({ port: 8080 }, server);

await web.start();

// curl -v https://localhost:8080/

Why?

When developing simple/small node HTTP services (eg: microservices) that don't require a big web framework, a simple web server that can started (and stopped) is needed.

There wasn't one before, so there is now.

License

MIT

Keywords

koa

FAQs

Package last updated on 02 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts