question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to Express app object

See original GitHub issue

Feature Request

Is your feature request related to a problem? Please describe. I’m writing a probot app that has a few custom Express routes, and I want access to the Express app object to call things such as app.set('trust proxy', true)

Describe the solution you’d like app.express, maybe?

Describe alternatives you’ve considered Currently I hack my way around it with this code:

const v0 = app.route('/api/v0');
v0.use((req, res, next) => {
  req.app.set('trust proxy', true);
  next();
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
danielrozenbergcommented, Mar 5, 2019

This sorta worked for me, but it makes my app a bit clunky (if I had written the app to begin with knowing the above it might’ve been better, but pivoting now is proving to be too difficult) - since I now know it’s possible, I guess this issue can be closed. Still, it would be nice to have (probot’s) app expose either the backing express app or at least expose some of these methods (set, get, use, and engine come to mind as useful methods to expose)

Anyways, just a thought - please feel free to close this if this isn’t a feature you think is worth adding

1reaction
JasonEtcocommented, Mar 5, 2019

Yeah, I was totally wrong. So, you can get to the underlying express server but its a bit of a hassle at the moment. Probot works by calling probot run, a CLI tool that loads up your code as a function after its done all of its setup. You can instead take a programmatic approach and control the entrypoint yourself:


const { createProbot } = require('probot') 

const probot = createProbot({
  id: process.env.APP_ID,
  port: process.env.PORT || 3000,
  secret: process.env.WEBHOOK_SECRET,
  cert: process.env.PRIVATE_KEY
})

// This'd be your existing code, you'd want to `require` it in...
const myProbotApp = app => {
  app.on('...')
}

probot.load(myProbotApp)

const expressApp = probot.server

That I know works 😁.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the best way to access the express 'app' object from ...
You can simply access app by req.app in your route handlers.
Read more >
How to use the app object in Express.js | by John Au-Yeung
The app object is the core object of an Express app. It has the methods to let us add middleware and route handlers....
Read more >
API Reference - Express 4.x
The app object conventionally denotes the Express application. ... You can access local variables in templates rendered within the application.
Read more >
How To Use the req Object in Express - DigitalOcean
Learn about using the req object in Express.js projects to examine calls from the client side, make HTTP requests, and handle incoming data ......
Read more >
Express/Node introduction - Learn web development | MDN
This object, which is traditionally named app , has methods for routing HTTP requests, configuring middleware, rendering HTML views, registering ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found