a simple HTTP server with some nice magik.
Install the package (globally) and start the server:
$ npm install -g magik-server$ magik-server
magik-server is a small webserver that is intended for use during the development of front-end web applications and websites. There are quite a few configuration options that can be set using command line switches, see below. Also there's the possibility to influence server responses using query string parameters.
- Getting started
To display all command line options use the
$ magik-server --help
In this section all the available command line options are listed.
Set the IP address the server is bound to. Default: localhost
$ magik-server -a 10.1.1.10
Enable sending of CORS headers.
$ magik-server --cors
Disable directory listing. By default, when no suitable file is found to serve, a directory listing will be displayed.
$ magik-server -D
Adds one or more extensions to use to look up the default index page. By default magikServer looks for:
html, htm, js.
# add one extension$ magik-server -e coffee# add more than one extension$ magik-server -e coffee, jade, styl
Displays a list of all available command line options
Enables the display of hidden files. By default, files starting with a dot are hidden in directory listings, use this switch to show them.
Adds one or more files that will be used as an index page. By default magikServer looks for files with these names in the document root,
index, default, main, app.
More files can be added as a comma delimeted list:
$ magik-server -i my-index, my-app, my-other-index
Adds the path to a custom 404 page. This path is relative to the document root.
$ magik-server -n error-pages/404.html
Automagically open the standard system web browser, after the server has started.
Sets the port number you wish to use for this server instance. If the port number is already in use, the next available port will be automagically selectd.
The default port is 8080
$ magik-server -p 8090
Sets the document root. Files from this folder will be served as if they are on
/ in the browser.
$ magik-server -r app
Sets the HTTP response code globally. Every response will have this status code. You may also force response codes by using a query string parameter. The default query string parameter is magik-status, but you can also change this to any URL save string.
$ magik-server -s 201$ magik-server -s my-status-param
Sets the response time globally in milliseconds. Every reponse will take (at least) this amount of time. You may also force response times by using a query string parameter. The default query string parameter is magik-time, but you can also change this to any URL save string.
$ magik-server -t 3000$ magik-server -t my-time-param
Sets the default character encoding of the files served. This defaults to UTF-8 and usually doesn't have to be changed.
$ magik-server -u cp-1252
Displays version information of magik-server
$ magik-server -v
magikServer allows you to use query string parameters to change certain behaviours. At this moment you can use these:
Sets the HTTP response status code for this request. That means, the response is certain to have the supplied status code. You can also change the name of the parameter during startup, using the
Sets the response time for this request. That means that the response will wait at least the supplied amount of milliseconds before it is send. You can also change the name of the parameter during startup, using the
Below you'll find a couple of commonly used ways to start up magik-server.
Start the server on localhost on port 8080
Show help info:
$ magik-server -h
Start the server on port 8090, set the document root to the app folder and set index to my-app.html
$ magik-server -p 8090 -r app -i my-app.html
Set the response time query string parameter to a
custom value, so you can make requests that will honour the set time value (in ms),
like this one:
$ magik-server -t wait
You can also set a global response time that will used for all responses
magik-server -t 3000
Set a custom HTTP response code query string parameter
so it can be used in requests like this one:
$ magik-server -s status
You can also set a global response status code that will always be returned
$ magik-server -s 202
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Licensed under the MIT license.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
_ _ _____ (_)| | / ___| _ __ ___ __ _ __ _ _ | | __\ `--. ___ _ __ __ __ ___ _ __ | '_ ` _ \ / _` | / _` || || |/ / `--. \ / _ \| '__|\ \ / / / _ \| '__| | | | | | || (_| || (_| || || < /\__/ /| __/| | \ V / | __/| | |_| |_| |_| \__,_| \__, ||_||_|\_\\____/ \___||_| \_/ \___||_| __/ | |___/