Imagine this sample Express app straight from the documentation:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(3000)
What is the idiomatic way to invoke the '/'
endpoint programmatically from a different point in the same application code? Assume that I already removed the last line app.listen(3000)
.
The reason for this is that I want to take something like express-pouchdb
and write an adapter for a different wire protocol, but leveraging the extensive routes
already defined. I want to invoke these routes directly from js code without going over the network.
The application has dozens of routes already defined so changing each one to direct function calls as suggested in the first comment is not an option.
UPDATE:
I tried calling app.route.dispatch()
but nothing comes back on the rsp object.