Save wayfarer-to-server routes to disk. Spiritual successor to brick-router.
$ npm install wayfarer-to-fs
const toServer = require('wayfarer-to-server')
const toFs = require('wayfarer-to-fs')
const wayfarer = require('wayfarer')
const filed = require('filed')
const router = toServer(wayfarer())
router.on('/', {
get: (req, res) => filed(__dirname + '/index.html').pipe(res))
})
toFs(router, __dirname + '/dist', (err) => {
if (err) throw err
})
Call all paths on a wayfarer-to-fs router and write them to a directory.
dir defaults to ./. An optional overrides argument can be passed in to
rename files:
// Write the `/` path as `dist/index.html`
const overrides = { '/': '/index.html' }
toFs(router, __dirname + '/dist', overrides, (err) => {
if (err) throw err
})
In development an application usually goes through 3 stages:
When switching stages it's common to throw out your build process, and start
from scratch. wayfarer-to-fs allows you to keep the same build process by
serving files both in-memory (for experimentation and servers) and being able
to write to the filesystem (for static pages).