Skip to content

Instantly share code, notes, and snippets.

@smcatala
Created May 17, 2019 22:04
Show Gist options
  • Save smcatala/9d2e2fd9d3873c901c49e5533d00c83a to your computer and use it in GitHub Desktop.
Save smcatala/9d2e2fd9d3873c901c49e5533d00c83a to your computer and use it in GitHub Desktop.
/**
* Copyright 2019 ZenyWay S.A.S., Stephane M. Catala
* @author Stephane M. Catala
* @license Apache Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* Limitations under the License.
*/
/**
* add an optional --rewrite (-r) argument that takes subarguments (see subarg module)
* for the connect-modrewrite middleware.
* other arguments are passed on unchanged to budo.
* eg: node budo-rw.js --rewrite ["^/some-long-hash/(:*) /$"] --live index.js
*/
const budo = require('budo')
const modrewrite = require('connect-modrewrite')
const subarg = require('subarg')
const args = process.argv.slice(2)
const { rewrite: { _: rewriteArgs } } = subarg(args, { alias: 'r' })
budo.cli(args, {
middleware: modrewrite(rewriteArgs)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment