0

我的上下文是下一个:

我有 3 个实例:1-public/Angular 2 用于在端口中的 lite-server 中运行的前端:3001 加载页面,3002 是 lite 服务器的配置 2-public/seneca 用于客户端与服务器通信在 3003 中 3-带有 mongodb 的服务器/seneca 位于端口 3000

我尝试执行一个测试并返回一个文本,但我只是超时。

这是我的文件:

在我添加角度逻辑之前,我尝试通过浏览器获取 seneca 客户端: http://localhost:3003/api/test

我得到一个 404 not found 并且在broser这个:Cannot GET /api/test

在塞内卡客户端我有这个:

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')
    })
  })

当我使用节点 scriptName.js 运行此代码段时,执行良好,但对于 seneca 行为,我得到了超时:

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

在服务器中我有这个:

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
        }
    }
}]

> thinkupvacations@1.0.0 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

希望能帮到我!!

问候!

4

1 回答 1

0

我将解决方案留给其他需要方向的人:

首先用小写的路由更改配置,就像你在开始时所说的那样:

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

并且需要像这样更改路线中的引脚:

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

而这项工作,:D

于 2016-11-28T14:08:05.277 回答