(db, routes, middlewares, argv)
| 36 | } |
| 37 | |
| 38 | function createApp(db, routes, middlewares, argv) { |
| 39 | const app = jsonServer.create() |
| 40 | |
| 41 | const { foreignKeySuffix } = argv |
| 42 | |
| 43 | const router = jsonServer.router( |
| 44 | db, |
| 45 | foreignKeySuffix ? { foreignKeySuffix } : undefined, |
| 46 | ) |
| 47 | |
| 48 | const defaultsOpts = { |
| 49 | logger: !argv.quiet, |
| 50 | readOnly: argv.readOnly, |
| 51 | noCors: argv.noCors, |
| 52 | noGzip: argv.noGzip, |
| 53 | bodyParser: true, |
| 54 | } |
| 55 | |
| 56 | if (argv.static) { |
| 57 | defaultsOpts.static = path.join(process.cwd(), argv.static) |
| 58 | } |
| 59 | |
| 60 | const defaults = jsonServer.defaults(defaultsOpts) |
| 61 | app.use(defaults) |
| 62 | |
| 63 | if (routes) { |
| 64 | const rewriter = jsonServer.rewriter(routes) |
| 65 | app.use(rewriter) |
| 66 | } |
| 67 | |
| 68 | if (middlewares) { |
| 69 | app.use(middlewares) |
| 70 | } |
| 71 | |
| 72 | if (argv.delay) { |
| 73 | app.use(pause(argv.delay)) |
| 74 | } |
| 75 | |
| 76 | router.db._.id = argv.id |
| 77 | app.db = router.db |
| 78 | app.use(router) |
| 79 | |
| 80 | return app |
| 81 | } |
| 82 | |
| 83 | module.exports = function (argv) { |
| 84 | const source = argv._[0] |
no outgoing calls
no test coverage detected
searching dependent graphs…