senecajs / seneca-web

Http route mapping for Seneca microservices.
MIT License
76 stars 44 forks source link

how to get the name param? #72

Closed foshantiger closed 8 years ago

foshantiger commented 8 years ago

I use the express and post data to add a product, everything seems ok except the "name" param, it's expected to get "iPhone" but actual got "Seneca/2.1.0/b0yoh6objcyt/1470717984357/15018/-" , is seems overrided by seneca?

what data I posted is : { "category":"mobile_phone", "name":"iPhone", "description":"description", "price":5999 }

And here is the code:

seneca.add({area: "product", action: "add"}, function(args,done) {
    var products = seneca.make$("products");
    console.log(args.name);

    products.category = args.category;
    products.name = args.name;
    products.description = args.description;
    products.price = args.price

    products.save$(function(err, product) {
      done(err, products.data$(false));
    });
  });

seneca.ready(function(err){
  seneca.act('role:web',{use:{
    prefix: '/products',
    pin: {area:'product',action:'*'},
    map:{
      add: {GET:false, POST:true}
    }
  }});

  var express = require('express');
  var app = express();
  app.use(require('body-parser').json());
  // This is how you integrate Seneca with Express
  app.use( seneca.export('web') );
  app.listen(3000);
  console.log('Server listen on port 3000...');
});
foshantiger commented 8 years ago

Solved. Just simply add the data property to the METHOD node,like that: add: {POST:{data:true}}, hope to make it as an example in the usage node :)

indr commented 8 years ago

This issue was fixed with PR #70 but seneca-web hasn't been published yet. npm install seneca-web via GitHub url.