Hi want to add apostrophy into my existing express project,
is there a way to export apostophy as a module and then use it in an express route?
what i’m looking for is like this:
const aposApp = require(‘custom_module’)
my_express_app.use(’/blog’,aposApp)
Hmm, we don’t currently provide the option of using an existing Express instance. However you can easily go the other way 'round. Apostrophe exposes the Express app object as apos.app
.
And Apostrophe also supports a prefix
option, which you could set to /blog
. When you use that option, there are actually two app objects, apos.baseApp
and apos.app
; apos.baseApp
is mounted at the root, while apos.app
is mounted at /blog
.
So you can attach your non-Apostrophe application code to baseApp
to get the effect I think you’re going for.
One of the best places to do that would be in an apostrophe:afterInit
promise event handler in one of your own Apostrophe modules.
Alternatively it probably wouldn’t be a terribly difficult PR to add the ability to inject an existing app
to the apostrophe-express
module.