mirror of
https://github.com/typicode/json-server.git
synced 2025-07-29 21:23:41 +08:00
Add --read-only option
This commit is contained in:
@ -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)
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user