1.0.4 • Published 6 years ago

good-server v1.0.4

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 years ago

Good Server

Launch simple express server from CLI (with JSON, static files hosting and file upload support)

Install CLI Tool

using npm (restricted ATM)

npm install -g good-server

with npx (restricted ATM)

npx good-server [Options]

using local code

cd good-server              (clone)
npm install -g ./

Command Line Interface

good-server --help

Usage: good-server [options]

Options:

-V, --version                          output the version number
-d, --dir [dir]                        Distrubution folder/directory (local or absolute path) (default: ./dist)
-u, --upload [dir]                     Upload folder/directory (local or absolute path) (default: ./upload)
-p, --port [port]                      Custom port for server (default: null)
-h, --host [host]                      Host for the server (default: localhost)
-s, --secure                           Secure host server (https)
-f, --file-input-name [fileInputName]  File input name (default: file)
--no-open                              Do not open URL in browser
-help                                  output usage information

Usage

  • good-server : Serve ./dist folder and use ./upload folder for upload files access/upload.
  • good-server --no-open : Do not open browser when server starts.
  • good-server -p 3000: Use port 3000 for server instead of default random available port.
  • good-server -h 192.168.0.9 : Use host 192.168.0.9 instead of default localhost.
  • good-server -s : Use https:// protocol instead of default http:// for server.
  • good-server -f image : Use image as file input name in request body instead of default file.
  • good-server -d ./build : Use ./build folder as distribution folder instead of default ./dist. This can be absolute path on the system as well, like /usr/share/build.
  • good-server -u ./files : Use ./files folder to serve/upload files instead of default ./upload. This can be absolute path on the system as well, like /usr/share/files.

API Access

  • GET /file.ext path on server URL will serve file.ext file from distribution folder.
  • GET /folder/file.ext path on server URL will server file.ext from folder directory inside distribution folder.
  • Server will add appropriate header while serving these files. For example, GET /json/users.json will serve users.json from json directory with application/json Content-Type response header.
  • GET /upload/file.ext will serve file.ext file from upload folder.
  • POST /upload route is used to upload a file. Make sure to use correct file input name while uploading a file to this route. This is key in your multipart form data. When you start a server, upload folder is automatically created if doesn't exist.

Websockets

v1.0.4+ supports websocket on the same port of web server. Default ping-pong event is message. Use Online client tool to test websocket functionality. Use http://localhost:{port} as socket.io server URL.

preview