1.0.21 • Published 1 month ago
@sumor/ssl-server v1.0.21
ssl-server
SSL Web Server with Express, Support HTTP/2
Installation
npm i @sumor/ssl-server --save
Prerequisites
Node.JS version
Require Node.JS version 16.x or above
require Node.JS ES module
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
Usage
Host a simple server
import createApp from "@sumor/ssl-server";
const app = createApp();
// listen on port 443 by default, and redirect 80 to https 443
await app.listen();
Add SSL files
Please add SSL files into root folder ssl
with the following names:
domain.crt
domain.key
ca.crt
(Optional, It will append to the certificate chain)
If not found, the server will generate a self-signed certificate.
If SSL files changed, it will auto-reload.
Features
it supports all express features, only difference is the listen
and close
method. Please refer below example for more details.
Add middlewares and routes
import createApp from "@sumor/ssl-server";
const app = createApp();
import bodyParser from 'body-parser';
// you can add any express middleware
app.use(bodyParser.json());
// add routes
app.get('/', (req, res) => {
res.send('Hello World!');
});
// listen is async function
await app.listen();
Force close server
import createApp from "@sumor/ssl-server";
const app = createApp();
// listen is async function
await app.listen();
// close is async function
await app.close();
Listen on custom port
import createApp from "@sumor/ssl-server";
const app = createApp();
// listen is async function
await app.listen(8443, 8080);
console.log(`Server is running on https://localhost:8443/`);
console.log(`Redirect server is running on http://localhost:8080/`);
1.0.21
1 month ago
1.0.20
1 month ago
1.0.19
2 months ago
1.0.18
2 months ago
1.0.17
2 months ago
1.0.16
2 months ago
1.0.15
2 months ago
1.0.14
2 months ago
1.0.13
2 months ago
1.0.12
3 months ago
1.0.11
3 months ago
1.0.2
3 months ago
1.0.1
3 months ago
1.0.0
3 months ago
1.0.10
3 months ago
1.0.9
3 months ago
1.0.8
3 months ago
1.0.7
3 months ago
1.0.6
3 months ago
0.0.0
3 months ago