MCPcopy
hub / github.com/typicode/json-server / createApp

Function createApp

src/cli/run.js:38–81  ·  view source on GitHub ↗
(db, routes, middlewares, argv)

Source from the content-addressed store, hash-verified

36}
37
38function 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
83module.exports = function (argv) {
84 const source = argv._[0]

Callers 1

startFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…