@ideadesignmedia/webserver.js v1.6.19
webserver.js
A highly customizable Express HTTP server with a few useful middleware functions.
Features
Automatically sanitize user inputs. Automatically serve gzipped files available in static folder. Supports HTTPS with automatic forwarding from HTTP.
Installation
yarn install @ideadesignmedia/webserver.js
Includes
index.js - Express HTTP Server Setup
bruteForce.js - Brute Force Protection Middleware
filestore.js - Filestore Routing
request-transformer.js - Request Transformer Routing
saveError.js - Error logging function
visits.js - Visitor logging middleware
upload.js - File upload middleware
server.conf - Sample Nginx Configuration
Basic Usage
const createServer = require('@ideadesignmedia/webserver.js');
const app = require('express').Router();
const configuration = { port: 3000, static: './public' };
/* Add routing using app. */
app.get('/', (req, res) => {
res.send('Hello World');
});
const server = createServer(configuration, app)
createServer(configuration = {}, routing = ExpressRouter, middleware = [ExpressMiddleware])
Creates an Express HTTP/HTTPS server.
Configuration
The configuration object is passed to the createServer function. It is used to configure the server. The following options are available:
port
- number - The port to listen on. Defaults to 3000.
static
- string - The path to the static files. Defaults to ./static
and will create the static folder if it does not exist.
HOST
- string - The hostname of the server. - optional
allowAllOrigins
- string - Allow all origins to access the server. when no HOST is specified this is set to true. - optional
allowHeaders
- string - The headers to allow. - optional
allowMethods
- The methods to allow. - optional
indexPage
- The index page to serve. Defaults to index.html
.
no404Redirect
- boolean - If true, will not redirect to the index page on 404. Defaults to false.
noSanitize
- boolean - If true, will not sanitize the request. Defaults to false.
JSON_SIZE
- number - The maximum size of the JSON body. Defaults to 100kb.
URL_SIZE
- number - The maximum size of the URL. Defaults to 100kb.
URL_PARAMETER_LIMIT
- number - The maximum number of URL parameters. Defaults to 100.
cert
- string - The path to the SSL certificate. - required for HTTPS
key
- string - The path to the SSL key. - required for HTTPS
Routing
The Express routing is passed to the createServer function and will run after middleware.
Middleware
The middleware array is passed to the createServer function and will run before static files but after access control, sanitization, options, request loging
Static Files
The static files are served from the static folder. The static folder is created if it does not exist. The static folder is created in the current working directory. The static folder can be changed by setting the static option in the configuration object.
Static files are served after middleware and routing.
4 months ago
4 months ago
8 months ago
8 months ago
12 months ago
1 year ago
12 months ago
12 months ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago