Method-override? in the actual combat of nodejs But it doesn't work. What's the problem?


const connect = require("connect");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const methodOverride = require("method-override");

const edit = function(req, res, next) {
  if ("GET" != req.method) {
    return next();
  }
  res.setHeader("Content-Type", "text/html");
  res.write("<form method="POST">");
  res.write("<input type="text" name="user[name]" value="allen"/>");
  res.write("<input type="hidden" name="_method" value="PUT"/>");
  res.write("<input type="submit" value="update" />");
  res.write("</form>");
  res.end();
};
const update = function(req, res, next) {
  console.log("-->", req.method, req.originalMethod, req.body);
  if ("PUT" != req.method) {
    return next();
  }
  res.end("update name to " + req.body.user.name);
};
connect()
  .use(morgan("dev"))
  .use(bodyParser.urlencoded({ extended: false }))
  .use(methodOverride("_method", { methods: ["post", "get"] }))
  .use(edit)
  .use(update)
  .listen(3000, function() {
    console.log("the server start at 3000");
  });
Oct.13,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4624f-44b87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4624f-44b87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?