Send nothing to Client

Hi there!

Meteor has some really nice packages, namely the accounts package and mongo driver! I’m wondering if it’s possible to just use Meteor as an API server and send nothing down to the client? Right now I’ve stripped out all but the basics however on the client lots of scripts are still being added, like packages/minimongo, packages/ddp etc!

If this isn’t possible, is there a way I can integrate the mongo driver Meteor uses in a vanilla Node app?

Thanks!

The client is served up by the webapp package. You can’t remove this package, but you can overwrite the client output completely by using any Connect-style middleware and then calling WebApp.connectHanders.use at the root url.

For example, if you want to build an api with Express, you can include the following server code:

import { WebApp } from 'meteor/webapp'
import express from 'express'

const app = express()
app.use('/example-api-route', function(req, res) {
  res.headers = {
    'Content-Type': 'application/json'
  }    
  res.end(JSON.stringify({ 
      message: "hello"
  }))
})
app.use('/', function(req, res) {
  // This will overwrite Meteor webapp client
  res.end()
}

// No need to 'listen' as this is already done by WebApp
WebApp.connectHandlers.use('/', app)

You’ll see that none of the client scripts are loaded.

1 Like

Brilliant! This is wonderful and exactly what I was looking for! Though it’s probably poor practice to use Meteor like this long term especially since I could accomplish what I’m after with vanilla node + the mongo driver, for short term goals this is wonderful!

Thank you!