This forum has moved, please join us on github discussions. We will keep these old posts available for reference. Thank you!

How to Add Apostrophy into an existing express instance?

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’)

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

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.baseApp is mounted at the root, while 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.

1 Like