Reputation: 1517
I am having the following code in my executable Js after the necessary imports.
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);
});
I am getting the following error while trying to run this example:
Seneca Fatal Error
Message: seneca: The export web has not been defined by a plugin.
Code: export_not_found
Details: { key: 'web' }
Thanks, sumit
Upvotes: 0
Views: 352
Reputation: 313
Example : 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)
}
})
Upvotes: 1
Reputation: 13
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
Upvotes: 1