-
Notifications
You must be signed in to change notification settings - Fork 0
A simple but fully featured webserver in NodeJS
License
paolobolzoni/simple_webserver
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Here is a minimal but fully featured web server written in Node javascript. It easily allows to deploy a websocket-enabled web server that works in http and https. Dependences: npm install websocket npm install toml You do not need the websocket module if you do not enable websockets. To generate a self-signed certificate for https: $ openssl genrsa -out key.pem $ openssl req -new -key key.pem -out csr.pem $ openssl x509 -req -days 3652 -in csr.pem -signkey key.pem -out cert.pem $ rm csr.pem Settings, relative paths start from the same directory where is server.js. server section, self explanatory. [server] ip = '0.0.0.0' port = 8080 client_dir = '../client' websocket = true https section, if enabled the server listens both https and http. But with the http protocol the server only understands GET requests (so not other verbs like POST or websockets) and redirects to the https protocol. The redirection address is taken from the value of fqdn. If the fqdn value is missing the redirection is based on the request host header. So: * if you are have a domain-validated certificate, put in fqdn the hostname it relates to, * if you are using a self-signed certificate, leave it empty. As exception, the server will serve via plain http the GET requests whose url starts with the keep_http value, if non-empty. The default value is for let's encrypt challenges. The port value is not mandatory, if present the server will listen http requests on the server.port and both http/https on the https.port. If absent the server will listen only on server.port to both protocols. Websockets are executed in wss if this section is enabled. [https] enabled = true port = 8443 key = './selfsig_keys/key.pem' cert = './selfsig_keys/cert.pem' fqdn = '' keep_http = '/.well-known/acme-challenge/' auth section, if enabled the server protects the pages with basic auth. If https is enabled, only the https expects the credentials, the http will just redirect to https. [auth] enabled = false realm = 'My site' name = 'name' password = 'password'
About
A simple but fully featured webserver in NodeJS
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published