I recently setup an http rest API on a sub route of a Meteor app. For anyone wondering how to add a basic express server here is a stripped down example serving a static index.html file. Useful for stuff like a /webhooks
endpoint or hosting autogenerated docs outputted from another library. express
isn’t even needed, but nice to use if using typescript.
const { Meteor } = require('meteor/meteor');
const { WebApp } = require('meteor/webapp');
const express = require('express');
const app = express();
app.get('*', (request, response) => {
response.send(Assets.getText('index.html')); // copy your index.html to the root /private directory
});
Meteor.startup(() => {
WebApp.rawConnectHandlers.use('/docs', app); // hijack the /docs endpoint from rest of the meteor app
});
One thing I’m not clear on is when to use WebApp.rawConnectHandlers
vs WebApp.connectHandlers
as they both seem to work.