Add --read-only option

This commit is contained in:
Typicode
2016-01-07 04:12:04 +01:00
parent d1205844c0
commit 672393e915
5 changed files with 37 additions and 14 deletions

View File

@ -32,6 +32,10 @@ module.exports = function () {
alias: 's',
description: 'Set static files directory'
},
'read-only': {
alias: 'ro',
description: 'Allow only GET requests'
},
snapshots: {
alias: 'S',
description: 'Set snapshots directory',
@ -52,6 +56,7 @@ module.exports = function () {
}
})
.boolean('watch')
.boolean('read-only')
.boolean('quiet')
.help('help').alias('help', 'h')
.version(pkg.version).alias('version', 'v')
@ -63,5 +68,4 @@ module.exports = function () {
.argv
run(argv)
}

View File

@ -42,18 +42,16 @@ function createApp (source, object, routes, argv) {
object
)
var defaults
if (argv.static) {
defaults = jsonServer.defaults({
logger: !argv.quiet,
static: path.join(process.cwd(), argv.static)
})
} else {
defaults = jsonServer.defaults({
logger: !argv.quiet
})
var defaultsOpts = {
logger: !argv.quiet,
readOnly: argv.readOnly
}
if (argv.static) {
defaultsOpts.static = path.join(process.cwd(), argv.static)
}
var defaults = jsonServer.defaults(defaultsOpts)
app.use(defaults)
if (routes) {