Step 1: Install Superstatic
npm install superstatic
Step 2: Create File Server
app.js
'use strict'
/* Superstatic is a an easy-to-use static file server developed by Firebase
* See: https://github.com/firebase/superstatic */
let superstatic = require('superstatic')
let options = {
/* Tells Superstatic to use the specified port and host
*
* In Bluemix, the VCAP_APP_PORT and VCAP_APP_HOST environment variables are
* used to tell applications which port and host they may use
* See: https://www.ng.bluemix.net/docs/#starters/nodejs/index.html#nodejs
*
* For local development, where those environment variables are not present,
* port 80 and host 'localhost' will be used */
port: process.env.VCAP_APP_PORT || 80,
host: process.env.VCAP_APP_HOST || 'localhost',
/* Tells Superstatic to set the current working directory
*
* In this case, __dirname is used as the current working directory, which is
* a Node.js specific global variable that contains the name of the directory
* that the currently executing script is located in
* See: https://nodejs.org/docs/latest/api/globals.html#globals_dirname
*
* Please note that the root configuration option listed below will be used
* relative to current working directory */
cwd: __dirname,
config: {
/* Tells Superstatic to set the root directory of the file server
*
* With this configuration, Superstatic will serve all files in the /www
* directory relative to this script file */
root: './www',
/* Tells Superstatic to "clean the URLs", meaning that all .html files will
* automatically have their file extensions dropped
*
* This also means that if an .html file extension is used at the end of the
* requested filename, Superstatic will automatically send a HTTP 301
* Redirect response
*
* Furthermore, index files do not require special handling; they will be
* redirected to URL of their directory by default: e.g. both '/index.html'
* and '/index' will be redirected to '/' */
clean_urls: true
},
/* Tells Superstatic to use gzip compression on the response body */
gzip: true,
/* Tells Superstatic to show network logging in the console */
debug: true
}
let server = superstatic.server(options)
/* Logs 'Ready to spit fire!' when Superstatic starts listening */
server.listen(() => console.log('Ready to spit fire!'))
Step 3: Run File Server
node app.js