0

在必要的导入之后,我的可执行 Js 中有以下代码。

seneca.ready(function(err){
seneca.act('role:web', {use:{
    prefix: '/products',
    pin: {area:'product', action:'*'},
    map: {
        list:{GET:true}
    }
}})
var express = require('express');
var app = express();
app.use(require('body-parser').json());

app.use( seneca.export('web') );
app.listen(8082);

});

尝试运行此示例时出现以下错误:

塞内卡致命错误

消息:seneca:导出网站尚未由插件定义。

代码:export_not_found

详细信息:{键:'web'}

谢谢,苏米特

4

2 回答 2

1

I am a beginner, I hope this snippet will be useful:

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

var app = Express();

var config = {
        Routes : [ {
            prefix : '/products',
            pin : {
                area : 'product',
                action : '*'
            },
            map : {
                list : {
                    GET : true
                }
            }

        }
        ],
       adapter : require('seneca-web-adapter-express'),
        context : app

    };

seneca.use(Web, config);

seneca.add({
    role: "web",
    area : "product",
    action : "list"
 }, function(req, done) {

     done(null,{result: "my list of products"});
});


seneca.ready(function(err) {    

     app.use(require('body-parser').json());

     app.use(seneca.export('web/context'));
     app.listen(8082);

    seneca.act('role:web,area:product,action:list',console.log);    

 });

Seneca web has recently encountered some changes and you should use an adapter for express. You can see examples here on the seneca-web github page

于 2016-11-10T08:32:41.267 回答
1

示例:index.js

const seneca = require('seneca')()
const express = require('express')()
const web = require('seneca-web')
const cors = require('cors')

var Routes = [{
  prefix: '/products',
  pin: 'area:product,action:*',
  map: {list: {GET: true}}
}]
express.use(cors())
var config = {
  routes: Routes,
  adapter: require('seneca-web-adapter-express'),
  context: express,
  options: {parseBody: true}
}
seneca.client()
.use(web, config)
.ready(() => {
  var server = seneca.export('web/context')()
  server.listen('8082', () => {
    console.log('server started on: 8082')
  })
})
seneca.add({area: 'product', action: 'list'}, function (args, done) {
  try {
    done(null, {response: 'Product List'})
  } catch (err) {
    done(err, null)
  }
})
于 2017-08-17T04:34:10.653 回答