Skip to content

Instantly share code, notes, and snippets.

@stolinski
Last active July 27, 2017 21:44
Show Gist options
  • Save stolinski/80525eaeafb44bc758245895f3400089 to your computer and use it in GitHub Desktop.
Save stolinski/80525eaeafb44bc758245895f3400089 to your computer and use it in GitHub Desktop.
Meteor Server Route Without Package
// ___ _
// | | _| |_
// | | |_ _|
// | | |_|
// | |___
// | |
// |_______|
//
// https://www.leveluptutorials.com/
// @leveluptuts
import { WebApp } from 'meteor/webapp';
// Basic
WebApp.connectHandlers.use('/hello', (req, res, next) => {
res.writeHead(200);
res.end(`Hello world from: ${Meteor.release}`);
});
// Getting Data From Post
WebApp.connectHandlers.use('/route-name', (req, res) => {
let body = '';
req.on('data', Meteor.bindEnvironment((data) => {
body += data;
}));
req.on('end', Meteor.bindEnvironment(() => {
const data = JSON.parse(body);
// Here is where you can do stuff with the data.
// I use this technique for writing webhook routes instead of adding
// an additional package.
res.writeHead(200);
res.end('Success');
}));
});
// More info here:
// https://docs.meteor.com/packages/webapp.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment