senecajs / seneca-web

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

seneca-web express error #116

Closed 1fabiopereira closed 7 years ago

1fabiopereira commented 7 years ago

I'm having the following error when trying to create an api with seneca-web: https://gist.github.com/1fabiopereira/d1c3434457de503cc680ed6571e575ca

Any idea what might be ?

tswaters commented 7 years ago

The error looks like you are passing pre-1.0 config. This has been updated after 1.0; use is now routes.

This applies to the initial configuration of SenecaWeb (if you provide initial routes), and when acting upon role:web.

Instead of:

seneca.use(SenecaWeb, {use: routes /* etc...*/ })

or

seneca.act('role:web', {use: routes})

It should be:

seneca.use(SenecaWeb, {routes /* etc...*/ }) 

or

seneca.act('role:web', {routes}) 
1fabiopereira commented 7 years ago

It's all right. I will try this and I report the result here.

1fabiopereira commented 7 years ago

Look I did not succeed.

Look my code:

//MathAPI.js
module.exports = function MathAPI(options) {

    // plugin initialization
    this.add('init:MathAPI', function (msg, respond) {

        console.log("Plugin inicializado");

        this.act('role:web', {
            use: {
                prefix: '/api',
                pin: 'role:api,path:*',
                map: {
                    calculate: {GET: true, suffix: '/:operation'}
                }
            }
        }, respond);
    });

    this.add('role:api,path:calculate', function (msg, respond) {
        // talking to the microservice
        this.act('role:math', {
            cmd: valid_ops[msg.operation],
            left: msg.left,
            right: msg.right
        }, respond);
    });

    // valid operations list
    var valid_ops = {sum: 'sum', product: 'product'};

};
//server.js
'use strict'

var Seneca = require('seneca')
var Express = require('Express')
var Web = require('seneca-web')

var config = {
  adapter: require('seneca-web-adapter-express'),
  context: Express()
}

var seneca = Seneca()
  .use('MathAPI')
  .use(Web, config)
  .ready(() => {
    var server = seneca.export('web/context')()
    server.listen('4000', () => {
      console.log('server started on: 4000')
    })
  })

Error when starting an application (node server.js):

Seneca Fatal Error
==================

Message: seneca: No matching action pattern found for { use: { pin: 'role:api,path:*', map: { calculate: [Object] } },  role: 'web' }, and no default result provided (using a default$ property).

Code: act_not_found

Details: { args: '{ use: { pin: \'role:api,path:*\', map: { calculate: [Object] } },  role: \'web\' }',
  plugin: {} }
tswaters commented 7 years ago

Replace

this.act('role:web', {
            use:

With

this.act('role:web', {
            routes:
1fabiopereira commented 7 years ago

Did not work ! I tried this:

        this.act('role:web', {
            routes: [{
                prefix: '/api',
                pin: 'role:api,path:*',
                map: {
                    calculate: {GET: true, suffix: '/:operation'}
                }
            }]
      ...

Even so, the error continues 😥

1fabiopereira commented 7 years ago

I created a repository with a code close to what I have, maybe this will help identify what is going wrong.

https://github.com/1fabiopereira/seneca-debug

tswaters commented 7 years ago

I just took a look at the repo, looks like you figured it out.... cheers!

1fabiopereira commented 7 years ago

Thanks for the help, I needed a thorough check since I am new with seneca, I think the problem was lack of experience. 😒