我试图用seneca and express
设置一个后端。当前,路由定义如下:
serviceRoutes: [
// a list of all supported routes
{
pin: 'role:auth,cmd:*',
prefix: '/api',
map: {
login: {
//GET: true,
POST: true,
alias: 'login'
},
logout: {
//GET: true,
POST: true,
alias: 'logout'
},
status: {
GET: true
}
}
}
]
为处理请求,添加了以下处理程序:
const seneca_instance = seneca()
.add('role:auth,cmd:login', (args, done) => {
//console.log('Role:auth, cmd:login \n==> ');
//console.log(args);
console.log('Login request received');
console.log(`request$.req? ${Object.keys(args.request$)}`);
done(args);
//args.request$.res.end("Logged in");
})
.add('role:auth,cmd:status', (args, done) => {
//console.log('Role:auth, cmd:status \n==> ');
//console.log(args.request$);
//
args.request$.res.end('Authentication server is up. Status: 200 OK'); // express res
done(args);
})
.use(seneca_web, web_ctx_config)
.ready(() => {
const server = seneca_instance.export('web/context')();
server.listen(config.servicePort, () => {
console.log('Authentication service started on localhost:4200/');
});
});
当我尝试curl -d '{"username":"uname","password":"pass"}' -H "Content-Type:application/json" http://localhost:4200/api/login
时,出现错误消息“无法开机自检到/ api / login”(很可能来自Express)。我尝试使用GET
,它工作正常(尝试时)curl http://localhost:4200/api/login
。另外,/api/status
可以按预期工作(已添加以测试服务)。
我在这里做错了什么?