How to use the json-server.low function in json-server

To help you get started, we’ve selected a few json-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github naholyr / json-server-gui / src / server.js View on Github external
}
if (indexOfMiddleware < app._router.stack.length) {
  app._router.stack[indexOfMiddleware] = new RouterLayer("/", {
    "sensitive": app._router.caseSensitive,
    "strict": false,
    "end": false
  }, serveStatic(path.resolve(appDir, "public")));
  console.log("Serve static directory:", path.resolve(appDir, "public"));
}

// DB file
app.low.path = path.resolve(appDir, "db.json");
if (!fs.existsSync(app.low.path)) {
  fs.writeFileSync(app.low.path, "{}");
}
app.low.db = require(app.low.path);

// Now the real HTTP server
var server = http.createServer(app);
app.port = process.env.PORT || 26080;

server.listen(app.port);

server.on("listening", function () {
  console.log("Server ready:", this.address());
});

// Emit on each request
function ping (name, req) {
  if (req.method !== "GET") {
    setTimeout(function () {
      process.emit("data-update");
github naholyr / json-server-gui / src / server.js View on Github external
var indexOfMiddleware = 0;
while (indexOfMiddleware < app._router.stack.length && app._router.stack[indexOfMiddleware].name !== "serveStatic") {
  indexOfMiddleware++;
}
if (indexOfMiddleware < app._router.stack.length) {
  app._router.stack[indexOfMiddleware] = new RouterLayer("/", {
    "sensitive": app._router.caseSensitive,
    "strict": false,
    "end": false
  }, serveStatic(path.resolve(appDir, "public")));
  console.log("Serve static directory:", path.resolve(appDir, "public"));
}

// DB file
app.low.path = path.resolve(appDir, "db.json");
if (!fs.existsSync(app.low.path)) {
  fs.writeFileSync(app.low.path, "{}");
}
app.low.db = require(app.low.path);

// Now the real HTTP server
var server = http.createServer(app);
app.port = process.env.PORT || 26080;

server.listen(app.port);

server.on("listening", function () {
  console.log("Server ready:", this.address());
});

// Emit on each request
function ping (name, req) {
github naholyr / json-server-gui / src / server.js View on Github external
var RouterLayer = require("json-server/node_modules/express/lib/router/layer");
var indexOfMiddleware = 0;
while (indexOfMiddleware < app._router.stack.length && app._router.stack[indexOfMiddleware].name !== "serveStatic") {
  indexOfMiddleware++;
}
if (indexOfMiddleware < app._router.stack.length) {
  app._router.stack[indexOfMiddleware] = new RouterLayer("/", {
    "sensitive": app._router.caseSensitive,
    "strict": false,
    "end": false
  }, serveStatic(path.resolve(appDir, "public")));
  console.log("Serve static directory:", path.resolve(appDir, "public"));
}

// DB file
app.low.path = path.resolve(appDir, "db.json");
if (!fs.existsSync(app.low.path)) {
  fs.writeFileSync(app.low.path, "{}");
}
app.low.db = require(app.low.path);

// Now the real HTTP server
var server = http.createServer(app);
app.port = process.env.PORT || 26080;

server.listen(app.port);

server.on("listening", function () {
  console.log("Server ready:", this.address());
});

// Emit on each request

json-server

[![Node.js CI](https://github.com/typicode/json-server/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/json-server/actions/workflows/node.js.yml)

SEE LICENSE IN ./LICENSE
Latest version published 2 months ago

Package Health Score

88 / 100
Full package analysis