I have trouble creating an API Endpoint in a Meteor 1.4.1 app using Restivus.
Here is my current code :
import { Restivus } from 'meteor/nimble:restivus'
import { Stripe } from '../stripe/stripe'
export const loadApi = function(){
console.log('loading api')
var Api = new Restivus({
enableCors: true,
prettyJson:true
})
Api.addRoute('/charge', {
post: {
action: function(){
console.log('* Charging customer')
console.log(this)
console.log(this.bodyparams)
Stripe.chargeCustomer('foobar',9900)
return {
statusCode:204,
body:'foobar'
}
}
}
})
console.log(Api)
}
Then I load this code on the server/main.js
Meteor.startup
function.
The API seems to be correctly defined, as the console.log
prints the Restivus object with the correct _routes
attribute.
However,sending a post request to http://localhost:3000/api/charge
does not trigger the function (the console.log
are not executed).
Any idea about what could be wrong with my code ? I use Meteor 1.4.1, so it might be a bug.
Try removing the leading slash from your route, so 'charge' instead of '/charge'.