multi-domain-static-server v1.1.2
multi-domain-static-server
A simple http server designed to serve static websites for multiple domains
This project is designed to make serving static HTML/CSS/JS websites for multiple domains easy. Whenever it receives an HTTP request, it uses the request hostname
to determine which content to serve, then checks for the presence of a folder with the same name in it's content directory. This enables you to point multiple domains at the same server and manage static websites just by populating your website directory with folders for each domain.
For example, say the domain mygreatwebsite.com
is pointed at the IP of a machine runing multi-domain-static-server
. When the server receives an HTTP request, it would check for the presense of the folder mygreatwebsite.com
in the folder defined in the DIRECTORY
env, which defaults to /var/www/html
.
This request:
HTTP GET mygreatwebsite.com/test.html
-will be served the file at-
/var/wwww/html/mygreatwebsite.com/test.html
If that doesn't exist, the server will return a 404
.
Install
$ npm install multi-domain-static-server
Usage
$ npm run start
A pm2
ecosystem file is also included. To run as a daemon, install pm2
and run:
$ pm2 start ecosystem.config.js
You may also use multi-domain-static-server
as a dependency in your project.
const WebsiteServer = require('multi-domain-static-server');
const server = new WebsiteServer({ directory: '/data/sites/'});
server.start();
server.stop();
Cofiguration
Configuration is pulled from the process env
, or a .env
file.
PORT
Number. Which port to run the server on. Default: 80
DIRECTORY
String. Which directory the static sites are served from. Default: /var/www/html/
VERBOSE
Boolean. Whether to log all requests to the console. Default: true
License
MIT © Jesse Youngblood
5 years ago