This manual is also available in HTML5.
Tiny web server with HTTPS support, static file serving,
subdomain support, middleware support, service worker support, and clastering support.
Tiny web server is disain for SPA (Single Page Application).
This project is a tiny web server that serves static files, supports HTTPS,
subdomains, middleware, and service workers.
When you run the server, it will serve the files in the public directory.
You can add your own files to the public directory and access them through the server.
The server also supports subdomains, so you can access different files based on the subdomain.
For example, if you have a file called index.html in the public directory,
you can access it through https://localhost/index.html.
If you have a file called index.html in the public/subdomain directory,
you can access it through https://subdomain.localhost/index.html.
The server also supports middleware, so you can add your own middleware functions to the server.
The server also supports service workers.
For testing uses a self-signed certificate, so you may see a warning in your browser when you access the server.
You can ignore the warning and proceed to the server.
Yor can mount the express.js style middleware to the server. Example:
const WebCluster = require('tiny-https-server');
const express = require('express');
const admin = express();
admin.get('/', (req, res) => {
res.send('Admin Homepage');
});
consr cluster = WebCluster({
//isDebug: true,
parallelism: 'auto 2'
}, function _initServer(server) {
server.addRequest({ path: '/admin' }, admin);
});
config-sets.jsontiny-https-server --help or tiny-https-server --parallelism='auto 1' --openYou can install tiny-https-server using this command:
npm install tiny-https-server
You can test tiny-https-server on your system using this command:
node ./node_modules/tiny-https-server/index.test
or in the tiny-https-server project directory:
npm test
You can use tiny-https-server in your project like this:
const WebCluster = require('tiny-https-server');
consr cluster = WebCluster({
isDebug: true, // Enable debug mode to see logs in the console
parallelism: 'auto 2' // Start 2 workers and scale up and down automatically
}, function _initServer(server) {
// Add a request handler for the /hello path
server.on('request', (req, res, next) => {
if (req.url === '/hello') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World');
return;
}
next();
});
});
This project is licensed under the MIT License.
Copyright © 2021 Manuel Lõhmus
Donations are welcome and will go towards further development of this project.