import { WebApp } from 'meteor/webapp'
WebApp.connectHandlers.use('/trial', (req, res) => {
// so we can call from website client-side
res.setHeader('Access-Control-Allow-Origin', '*')
// pre-flight request
if (req.method == 'OPTIONS') {
res.writeHead(200)
res.end()
return
}
req.on('data', Meteor.bindEnvironment((data) => {
res.setHeader('Content-Type', 'application/json')
try {
var params = JSON.parse(data.toString())
}
catch(e) {
res.writeHead(400)
res.end()
return
}
Meteor.defer(() => YOUR_FUNCTION(params))
res.writeHead(200)
res.end(JSON.stringify({ status: 'ok' }))
}))
})