Skip to content

Instantly share code, notes, and snippets.

@techieshark
Created August 29, 2019 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techieshark/621528c64c73851a6e28d6bb4b805cc3 to your computer and use it in GitHub Desktop.
Save techieshark/621528c64c73851a6e28d6bb4b805cc3 to your computer and use it in GitHub Desktop.
node: setAllowHeader()
import { NextFunction, Request, Response } from 'express';
/**
* Sets Allow header.
*
* "The Allow header lists the set of methods support by a resource.
* This header must be sent if the server responds with a 405 Method Not Allowed
* status code to indicate which request methods can be used."
*
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow
*/
export const setAllowHeader = (req: Request, res: Response, next: NextFunction) => {
res.set('allow', 'GET, POST, OPTIONS');
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment