trailsjs / trailpack-express

:package: Express Trailpack
MIT License
12 stars 15 forks source link

Additional Express Configuration #48

Closed disciple-dev closed 8 years ago

disciple-dev commented 8 years ago

It would be nice to be able to set a few more options with express than seems to be possible, now.

I could be completely missing this, but is there doesn't seem to be a way to do something like app.disable() or app.enable(), say if you wanted to disable X-Powered-By or enable trust proxy

There's a few ways to work around this, but It would be handy.

jaumard commented 8 years ago

Hi @iwritesomecode, Is this not possible by adding a custom middleware ? If not any idea on how it can work in Trails ?

disciple-dev commented 8 years ago

It is possible for some things, but middleware are run on every request, which isn't ideal. I don't want to be setting trust proxy on every request!

In the case of this module, I'm not sure what best practice would be. This hack works, but it's about the most painless way I found of doing it without changing this trailpack:

in myProject/server.js:

server.start()
.then(app => app.packs.express.server.disable('x-powered-by'))
.catch(err => server.stop(err))

Obviously not ideal.

I'm not sure the best way to get around to implementing it; I'll have a whack at it this weekend, perhaps. Since the express app is intialized by the trailpack, the trailpack could look for extra options in config/web.js without affecting any parent classes, I think.

jaumard commented 8 years ago

Ok I'll look at this, make sense to have kind of init method available into config/web.js that can be use for this kind of stuff. Thanks for the explanation :)

scott-wyatt commented 8 years ago

I think an init method in config/web.js is a nice idea.

jaumard commented 8 years ago

Alive in v1.1.0 guys :)