Skip to content

Instantly share code, notes, and snippets.

@tadeaspetak
Created January 30, 2022 14:57
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 tadeaspetak/ec3a739548fd242b1d3145e0a43d428f to your computer and use it in GitHub Desktop.
Save tadeaspetak/ec3a739548fd242b1d3145e0a43d428f to your computer and use it in GitHub Desktop.
const api = express.Router();
// enforce `application/json` content type on all api endpoints
api.use((req, res, next) => {
if (req.headers["content-type"] !== "application/json") {
res.status(400).json({ message: "Invalid content type." });
} else {
next();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment