Last active
July 27, 2017 21:44
-
-
Save stolinski/80525eaeafb44bc758245895f3400089 to your computer and use it in GitHub Desktop.
Meteor Server Route Without Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ___ _ | |
// | | _| |_ | |
// | | |_ _| | |
// | | |_| | |
// | |___ | |
// | | | |
// |_______| | |
// | |
// 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