Created
February 2, 2024 06:25
-
-
Save ganeshkbhat/911b90a3b7d150d5bb59fc93eeabfa0e to your computer and use it in GitHub Desktop.
after-middleware alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// after-middleware alternative - 2 | |
const express = require('express'); | |
const app = express(); | |
const beforeMiddleware = function(req, res, next) { | |
console.log('Before middleware triggered'); | |
next(); | |
} | |
const responseHandler = function(req, res, next) { | |
console.log('Response Action implementation triggered with response instead of send'); | |
res.status(200).send({"response":"fine-as-normal"}); | |
} | |
const afterMiddleware = function(req, res, next) { | |
console.log('After middleware triggered'); | |
} | |
app.get('/implement', beforeMiddleware, responseHandler, afterMiddleware); | |
app.listen(9001, '127.0.0.1', function() { | |
console.log('Server started at port ' + 'localhost' + ':' + 9001); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment