wwl*_*wli 8 node.js express restify
我正在使用restify建筑api,它很棒.但我需要在同一个应用程序中渲染一些网页.
我可以在一个应用程序中一起使用express和restify吗?
这是app.js中restify服务器的代码
var restify = require('restify');
var mongoose = require('mongoose');
var server = restify.createServer({
name : "api_app"
});
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());
mongoose.connect('mongodb://localhost/db_name');
server.get('/', routes.index);
server.post('/api_name', api.api_name);
server.listen(8000 ,"localhost", function(){
console.log('%s listening at %s ', server.name , server.url);
});
Run Code Online (Sandbox Code Playgroud)
如何在同一个app.js中创建快速服务器?
谢谢
对于所有意图和目的,restify和express不能在同一节点进程中共存,因为出于不幸的原因,它们都试图覆盖http请求/响应API的原型,并最终导致不可预测的行为,什么.我们可以安全地在快递应用程序中使用restify客户端,但不能使用两台服务器.
如果你需要REST API和普通网页,我认为你不需要再坚持restify了。您始终可以只使用express,并在其上构建API而不是restify,因为express几乎可以完成restify所做的所有事情。
| 归档时间: |
|
| 查看次数: |
4591 次 |
| 最近记录: |