Coder Social home page Coder Social logo

wormss / express-gone Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 3 KB

Simple express middleware for displaying GONE (410) status code for a set of paths

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%
nodejs expressjs status-codes

express-gone's Introduction

express-gone

Simple express middleware for displaying GONE (410) status code

NPM Version NPM Downloads

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install express-gone --save

Example

app.use("/somefile", require("express-gone")());
let gone = require("express-gone");
app.use("/somefile", gone());

More examples below

API

gone([options]);

options

Optional argument for changing default response.

options.status

The status code to send in the response. res.status(status); api
default is 410.

options.redirect

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.

options.type

The content type of the response. res.type(type); api
default is "text"

options.render

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.

options.renderLocals

The variables to pass to the render view. res.render(render, renderLocals); api
default is undefined.

options.send

The content body of the response. res.send(send); api
default is "Gone!".

More Examples

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

defaults
// Status Code: 410, Content-Type: "text/plain"
// body: "Gone"
app.use(paths, gone());
render
// 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" } }));
message
// 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" }));
redirect
// Status Code: 301, Location: "/no-file"
app.use(paths, gone({ status: 301, redirect: "/no-file" }));

License

ISC

express-gone's People

Contributors

wormss avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.