Simple express middleware for displaying GONE (410) status code
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install express-gone --save
app.use("/somefile", require("express-gone")());
let gone = require("express-gone");
app.use("/somefile", gone());
Optional argument for changing default response.
The status code to send in the response. res.status(status);
api
default is 410.
The redirect location to send in the response. res.redirect(status, redirect);
api
default is undefined.
note: If redirect is used; type, render or message is ignored.
note: Most clients (browsers) do not play nicely with redirect when status code is not 3xx. It is recommended to use render or message instead of redirect.
The content type of the response. res.type(type);
api
default is "text"
The name of the view for the response to render. res.render(render);
api
default is undefined.
note: If render is used, message is ignored.
The variables to pass to the render view. res.render(render, renderLocals);
api
default is undefined.
The content body of the response. res.send(send);
api
default is "Gone!".
In express paths
can be a single path string
or express path pattern
or regular expression
or array with any of the previous types
For more information on paths see path-examples
// Status Code: 410, Content-Type: "text/plain"
// body: "Gone"
app.use(paths, gone());
// Status Code: 410, Content-Type: "text/html" (default for express is text/html)
// body: [what ever your render view looks like, with possibly the title "File Removed"]
app.use(paths, gone({ render: "error/gone", renderLocals: { title: "File Removed" } }));
// Status Code: 410, Content-Type: "text/plain"
// body: "File has gone, not even a ghost exists"
app.use(paths, gone({ type: "text", send: "File has gone, not even a ghost exists" }));
// Status Code: 301, Location: "/no-file"
app.use(paths, gone({ status: 301, redirect: "/no-file" }));