Search code examples
expressseneca

i cant excute a Seneca Express url test


my context is the next:

i have 3 instances: 1- public/Angular 2 for frontend running in a lite-server in port: 3001 load the page and 3002 is the configuration for lite server 2- public/seneca for client to comunicate to server is in 3003 3- server/seneca with mongodb is in port 3000

i try just execute a test and return a text but i just get timeout.

this are my files:

Before i add the logic in angular i try to get the seneca client via browser put this: http://localhost:3003/api/test

i get a 404 not found and in broser this: Cannot GET /api/test

in seneca client i have this:

var Seneca = require("seneca");
var Express = require("express");
var Web = require("seneca-web");

var senecaProvince = require("seneca")().client({
  host: "127.0.0.1", //"192.168.0.2",
  port: 3000 //8080
});

function senecaProvinceApi(options) {
  var seneca = this;

  /**
   * test
   */
  seneca.add({
    role: "web",
    area: "ui",
    action: "test"
  }, function(args, done) {
    senecaProvince.act({
      area: "province",
      action: "test"
    }, function(err, result) {
      done(err, result);
    });
  });

  /**
   * Gets the full list of provinces
   */
  seneca.add({
    area: "ui",
    action: "provinces"
  }, function(args, done) {
    senecaProvince.act({
      area: "province",
      action: "fetch"
    }, function(err, result) {
      done(err, result);
    });
  });

  /**
   * Get a product by id.
   */
  seneca.add({
    area: "ui",
    action: "provincebyid"
  }, function(args, done) {
    senecaProvince.act({
      area: "province",
      action: "fetch",
      criteria: "byId",
      id: args.id
    }, function(err, result) {
      done(err, result);
    });
  });
}

var config = {
  Routes: [{
    prefix: '/api',
    pin: {
      area: 'ui',
      action: '*'
    },
    map: {
      test: {
        GET: true
      },
      province: {
        GET: true
      },
      provincebyid: {
        GET: true,
        suffix: '/:id'
      }
    }
  }],
  adapter: require('seneca-web-adapter-express'),
  context: Express()
};

var seneca = Seneca()
  .use(senecaProvinceApi)
  .use(Web, config)
  .ready(() => {
    var clientSeneca = seneca.export('web/context')()

    seneca.act('role:web,area:ui,action:test', console.log);

    clientSeneca.listen('3003', () => {
      console.log('server started on: 3003')
    })
  })

when i run this snippet with node scriptName.js execute good but for the seneca act i get a timeout:

server started on: 3003
["client","invalid_origin",{"host":"127.0.0.1","port":3000,"pg":"","type":"web",
"id":"host:127.0.0.1,pg:,port:3000","role":"transport","hook":"client","plugin$"
:{"name":"client$"},"fatal$":true,"meta$":{"id":"7exetnw7bpf7/pdf1qyqak0a7","tx"
:"pdf1qyqak0a7","pattern":"hook:client,role:transport,type:web","action":"(9xy5c
9gfhsxq)","plugin_name":"transport","plugin_tag":"-","prior":{"chain":[],"entry"
:true,"depth":0},"start":1480200582782,"sync":true},"tx$":"pdf1qyqak0a7","path":
"/act","protocol":"http","timeout":5555,"max_listen_attempts":11,"attempt_delay"
:222,"serverOptions":{}},{"kind":"res","res":{"type":"Buffer","data":[67,97,110,
110,111,116,32,80,79,83,84,32,47,97,99,116,10]},"error":{"type":"Buffer","data":
[67,97,110,110,111,116,32,80,79,83,84,32,47,97,99,116,10]},"sync":true,"time":{"
client_recv":1480200582830}}]
{"notice":"seneca: Action action:test,area:ui,role:web failed: [TIMEOUT].","code
":"act_execute","err":{"eraro":true,"orig":{},"code":"act_execute","seneca":true
,"package":"seneca","msg":"seneca: Action action:test,area:ui,role:web failed: [
TIMEOUT].","details":{"message":"[TIMEOUT]","pattern":"action:test,area:ui,role:
web","instance":"Seneca/zdo3fusqyffz/1480200582728/13348/3.2.2/-","orig$":{},"me
ssage$":"[TIMEOUT]","plugin":{}},"callpoint":"at Object.act_tm [as ontm] (C:\\De
vProjects\\ThinkUpVacations\\public\\node_modules\\seneca\\seneca.js:1024:46)"},
"actid":"l15ybf5u5956/6g5ugs5h8r1b","msg":{"role":"web","area":"ui","action":"te
st","meta$":{"id":"l15ybf5u5956/6g5ugs5h8r1b","tx":"6g5ugs5h8r1b","pattern":"act
ion:test,area:ui,role:web","action":"(vq1mjuzautzr)","plugin_name":"senecaProvin
ceApi","plugin_tag":"-","prior":{"chain":[],"entry":true,"depth":0},"start":1480
200582794,"sync":true},"plugin$":{"name":"senecaProvinceApi","tag":"-"},"tx$":"6
g5ugs5h8r1b"},"entry":true,"prior":[],"meta":{"plugin_name":"senecaProvinceApi",
"plugin_tag":"-","plugin_fullname":"senecaProvinceApi","raw":{"role":"web","area
":"ui","action":"test"},"sub":false,"client":false,"args":{"role":"web","area":"
ui","action":"test"},"rules":{},"id":"(vq1mjuzautzr)","pattern":"action:test,are
a:ui,role:web","msgcanon":{"action":"test","area":"ui","role":"web"},"priorpath"
:""},"client":false,"listen":false,"transport":{},"kind":"act","case":"ERR","dur
ation":22290,"level":"error","when":1480200605089}
{ Error: [TIMEOUT]
    at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\node_modu
les\seneca\seneca.js:1024:46)
    at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacations\pu
blic\node_modules\gate-executor\gate-executor.js:216:16)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  eraro: true,
  orig:
   Error: [TIMEOUT]
       at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\node_m
odules\seneca\seneca.js:1024:46)
       at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacations
\public\node_modules\gate-executor\gate-executor.js:216:16)
       at ontimeout (timers.js:365:14)
       at tryOnTimeout (timers.js:237:5)
       at Timer.listOnTimeout (timers.js:207:5),
  code: 'act_execute',
  seneca: true,
  package: 'seneca',
  msg: 'seneca: Action action:test,area:ui,role:web failed: [TIMEOUT].',
  details:
   { message: '[TIMEOUT]',
     pattern: 'action:test,area:ui,role:web',
     fn: [Function],
     cb: [Function: bound ],
     instance: 'Seneca/zdo3fusqyffz/1480200582728/13348/3.2.2/-',
     'orig$':
      Error: [TIMEOUT]
          at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\nod
e_modules\seneca\seneca.js:1024:46)
          at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacati
ons\public\node_modules\gate-executor\gate-executor.js:216:16)
          at ontimeout (timers.js:365:14)
          at tryOnTimeout (timers.js:237:5)
          at Timer.listOnTimeout (timers.js:207:5),
     'message$': '[TIMEOUT]',
     plugin: {} },
  callpoint: 'at Object.act_tm [as ontm] (C:\\DevProjects\\ThinkUpVacations\\pub
lic\\node_modules\\seneca\\seneca.js:1024:46)' }
{"notice":"seneca: Action  failed: [TIMEOUT].","code":"act_execute","err":{"erar
o":true,"orig":{},"code":"act_execute","seneca":true,"package":"seneca","msg":"s
eneca: Action  failed: [TIMEOUT].","details":{"message":"[TIMEOUT]","pattern":""
,"instance":"Seneca/gags37ukcd3c/1480200582435/13348/3.2.2/-","orig$":{},"messag
e$":"[TIMEOUT]","plugin":{}},"callpoint":"at Object.act_tm [as ontm] (C:\\DevPro
jects\\ThinkUpVacations\\public\\node_modules\\seneca\\seneca.js:1024:46)"},"act
id":"244bca4nlvw8/5h4dtyfolw1g","msg":{"area":"province","action":"test","meta$"
:{"id":"244bca4nlvw8/5h4dtyfolw1g","tx":"5h4dtyfolw1g","pattern":"","action":"(3
7e0fxenvdtu)","plugin_name":"client$","plugin_tag":"-","prior":{"chain":[],"entr
y":true,"depth":0},"start":1480200582804,"sync":true},"plugin$":{"name":"client$
","tag":"-"},"tx$":"5h4dtyfolw1g"},"entry":true,"prior":[],"meta":{"plugin_name"
:"client$","plugin_tag":"-","plugin_fullname":"client$","raw":{"client$":true,"i
nternal$":{"catchall":true}},"sub":false,"client":true,"args":{},"rules":{},"id"
:"(37e0fxenvdtu)","pattern":"","msgcanon":{},"priorpath":""},"client":true,"list
en":false,"transport":{},"kind":"act","case":"ERR","duration":22290,"level":"err
or","when":1480200605095}
{"notice":"seneca: Action  failed: [TIMEOUT].","code":"act_execute","err":{"erar
o":true,"orig":{},"code":"act_execute","seneca":true,"package":"seneca","msg":"s
eneca: Action  failed: [TIMEOUT].","details":{"message":"[TIMEOUT]","pattern":""
,"instance":"Seneca/gags37ukcd3c/1480200582435/13348/3.2.2/-","orig$":{},"messag
e$":"[TIMEOUT]","plugin":{}},"callpoint":"at Object.act_tm [as ontm] (C:\\DevPro
jects\\ThinkUpVacations\\public\\node_modules\\seneca\\seneca.js:1024:46)"},"act
id":"l15ybf5u5956/6g5ugs5h8r1b","msg":{"role":"web","area":"ui","action":"test",
"meta$":{"id":"l15ybf5u5956/6g5ugs5h8r1b","tx":"6g5ugs5h8r1b","pattern":"action:
test,area:ui,role:web","action":"(vq1mjuzautzr)","plugin_name":"senecaProvinceAp
i","plugin_tag":"-","prior":{"chain":[],"entry":true,"depth":0},"start":14802005
82794,"sync":true},"plugin$":{"name":"senecaProvinceApi","tag":"-"},"tx$":"6g5ug
s5h8r1b"},"entry":true,"prior":[],"meta":{"plugin_name":"senecaProvinceApi","plu
gin_tag":"-","plugin_fullname":"senecaProvinceApi","raw":{"role":"web","area":"u
i","action":"test"},"sub":false,"client":false,"args":{"role":"web","area":"ui",
"action":"test"},"rules":{},"id":"(vq1mjuzautzr)","pattern":"action:test,area:ui
,role:web","msgcanon":{"action":"test","area":"ui","role":"web"},"priorpath":""}
,"client":false,"listen":false,"transport":{},"kind":"act","case":"ERR","duratio
n":22302,"level":"error","when":1480200605096}
{ Error: [TIMEOUT]
    at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\node_modu
les\seneca\seneca.js:1024:46)
    at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacations\pu
blic\node_modules\gate-executor\gate-executor.js:216:16)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  eraro: true,
  orig:
   Error: [TIMEOUT]
       at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\node_m
odules\seneca\seneca.js:1024:46)
       at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacations
\public\node_modules\gate-executor\gate-executor.js:216:16)
       at ontimeout (timers.js:365:14)
       at tryOnTimeout (timers.js:237:5)
       at Timer.listOnTimeout (timers.js:207:5),
  code: 'act_execute',
  seneca: true,
  package: 'seneca',
  msg: 'seneca: Action  failed: [TIMEOUT].',
  details:
   { message: '[TIMEOUT]',
     pattern: '',
     fn: { [Function: transport_client] id: 'host:127.0.0.1,pg:,port:3000' },
     cb: [Function],
     instance: 'Seneca/gags37ukcd3c/1480200582435/13348/3.2.2/-',
     'orig$':
      Error: [TIMEOUT]
          at Object.act_tm [as ontm] (C:\DevProjects\ThinkUpVacations\public\nod
e_modules\seneca\seneca.js:1024:46)
          at Timeout.timeout_check [as _onTimeout] (C:\DevProjects\ThinkUpVacati
ons\public\node_modules\gate-executor\gate-executor.js:216:16)
          at ontimeout (timers.js:365:14)
          at tryOnTimeout (timers.js:237:5)
          at Timer.listOnTimeout (timers.js:207:5),
     'message$': '[TIMEOUT]',
     plugin: {} },
  callpoint: 'at Object.act_tm [as ontm] (C:\\DevProjects\\ThinkUpVacations\\pub
lic\\node_modules\\seneca\\seneca.js:1024:46)' } undefined

and in the server i have this:

var Seneca = require("seneca");
var Web = require("seneca-web");
var Express = require('express');
var Routes = require('./routes');
var provincePlugin = require('./provincePlugin');

/*
seneca.use('mongo-store', {
    name: 'DoMyTrip-TouristZone',
    host: '127.0.0.1',
    port: 27017,
    options: {}
})
*/

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

var seneca = Seneca()
    .use(provincePlugin)
    .use(Web, config)
    .ready(() => {
        //express.use(require("body-parser").json());
        var server = seneca.export('web/context')()

        server.listen('3000', () => {
            console.log('server started on: 3000')
        })

        //seneca.act('role:web,area:province,action:test', console.log);
    })

"use strict";

module.exports = function provincePlugin(options) {

    var seneca = this;

    seneca.add({
        role: "web",
        area: "province",
        action: "test"
    }, function(req, done) {
        done(null, {
            result: "Hello World From Seneca"
        });
    });

    seneca.add({
        area: "province",
        action: "fetch"
    }, function(args, done) {
        var provinces = this.make("provinces");
        provinces.list$({}, done);
    });

    seneca.add({
        area: "province",
        action: "fetch",
        criteria: "byId"
    }, function(args, done) {
        var province = this.make("provinces");
        province.load$(args.id, done);
    });
}

'use strict'

module.exports = [{
    prefix: '/provinces',
    pin: {
        area: 'province',
        action: '*'
    },
    map: {
        fetch: {
            GET: true
        },
        test: {
            GET: true
        }
    }
}]

> [email protected] start C:\DevProjects\ThinkUpVacations\server\province
> node app/index.js

{"kind":"notice","notice":"hello seneca w1eo77330jgi/1480188397177/4280/3.2.2/-","level":"info","when":1480188397212}
(node:4280) DeprecationWarning: 'root' is deprecated, use 'global'
server started on: 3000

I hope can help me!!

Greets!


Solution

  • I leave the solution for someone else needs an orientation:

    First change the config with routes in lower case how you say at begin:

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

    and need change the pin in the routes like this:

    pin: 'role:web,area:province,action:*',

    And this work, :D