servbot
A small dev server for local static site development. Essentially a wrapper around http.Server. Fork of servor.
import servbot from 'servbot';
const server = servbot({
root: './public/',
reload: true,
fallback: 'index.html'
});
server.listen(8080);
This is an opinionated fork with some intentional exclusions and smaller scope, and some ideas taken from nativew/serve.
Install
npm install servbot --save-dev
Usage
See types in index.d.ts. servbot accepts a single argument, ServbotOptions
; and returns an instance of ServbotServer
. See below for the default options.
import servbot from 'servbot';
const server = servbot({
root: '.',
reload: false,
fallback: '',
ignores: [],
credentials: undefined
});
server.listen(8080);
server.close((err) => {
if (err) process.exit();
});
Using manual reload
Instead of including a filewatcher to automatically reload your app on file changes, servbot includes a manual reload feature. Most modern front-end development build tools already include a built-in watch feature (esbuild, rollup, webpack, parcel, etc.) that can be leveraged by servbot. For an example with rollup, see here.
Outside of build tools, you can also use something like cheap-watch or watchlist. See below for an example using watchlist:
import servbot from 'servbot';
import { watch } from 'watchlist';
const server = servbot({
root: './example/static/',
reload: true,
fallback: 'index.html'
});
server.listen(8080);
(async () => {
await watch(['./example/static/'], async () => {
console.log('change detected! reloading...');
server.reload();
});
})();
To-Do
- Tests for SPA example
- HTTP/2 support