1.6.19 • Published 4 months ago

@ideadesignmedia/webserver.js v1.6.19

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

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.

1.6.19

4 months ago

1.6.18

4 months ago

1.6.17

8 months ago

1.6.16

8 months ago

1.6.13

12 months ago

1.6.12

1 year ago

1.6.15

12 months ago

1.6.14

12 months ago

1.6.9

2 years ago

1.6.11

1 year ago

1.6.8

2 years ago

1.6.10

1 year ago

1.6.7

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.10

2 years ago

1.5.11

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago