Local static server
Everything start from here
.
Node.js >= 8.0
-
Look up available port automatically, which means multiple instances without specifying port.
-
Custom routes by scripting
here.js
. -
Live reload.
-
Support https.
-
Add ip address to your server, which makes your server available to other devices.
-
Resolve get, post... every method into local files, for ajax.
-
Respond files without extension as
application/json
for ajax. -
Open default browser after server launched.
-
When the server is on, press
enter
will open the browser.
[sudo] npm install -g @vivaxy/here
In your local folder, type here
and it goes!
here -p 8888
or
here --port 8888
Default port is 3000
.
here -S
or
here --ssl
here -G
or
here --gzip
here -d test
or
here --directory test
Default directory is ./
.
here -w 3
or
here --watch
Default interval is 0 second.
Recommend to set reload interval to page reload time.
here -s
or
here --silent
here --ip localhost
or
here --ip private
or
here --ip public
Default IP is public
.
here -l
or
here --log 0
Write here.js
in server base directory.
let db = {
tobi: {
name: 'tobi',
age: 21
},
loki: {
name: 'loki',
age: 26
},
jane: {
name: 'jane',
age: 18
}
};
module.exports = [
{
method: 'get',
path: '/pets',
data () {
let names = Object.keys(db);
return names.map((name) => {
return db[name];
});
}
},
{
method: 'get',
path: '/pets/:name',
data () {
let name = this.params.name;
let pet = db[name];
if (!pet) {
return {
error: `cannot find pet ${name}`
};
} else {
return pet;
}
}
}
];
See koa-router document for more detail.
- puer not support post, respond files without extension as
application/octet-stream
- anywhere not support post, and not support reload
- browsersync not support post, respond files without extension as
application/octet-stream
- serve