羽毛可以与羽毛侧面管理的溃败共存吗

  • 本文关键字:羽毛 管理 侧面 feathersjs
  • 更新时间 :
  • 英文 :


我们有一个大型应用程序,它使用express进行休息,使用primus进行套接字路由。很难一下子把所有的羽毛都变成羽毛。我正在考虑分阶段的方法,我可以选择一些路线并将其转换为服务,当然,任何新的路线都将遵循服务模式。我将慢慢迁移应用程序的其余部分。

客户端目前使用primus和angularjs$http与nodejs进行通信。

我们目前的设置看起来像

var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
const csrf = require('csurf');
var Primus = require('primus');
var SocketService = require('./../services/socket-service'); ////this handles existing socket routes from primus client using spark.write
var routesUtils = require('../utilities/routes-utility');
var _ = require('lodash');
module.exports = function(isClusteredDeploy) {
var app = express();
var server = http.createServer(app);
var primus = new Primus(server, {transformer: 'uws'});
var socketService = SocketService(primus); 
var commonSocketRoute, commonRoute;
//primus.library();
//primus.save(__dirname + '/primus-client.js');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json({
strict: false,
limit: '1mb'
}));
app.use(cookieParser());
app.use(csrf({ cookie: true }));
app.use(function (err, req, res, next) {
if (err.code !== 'EBADCSRFTOKEN') {
return next(err);
}
res.status(403);
res.send();
});
app.use(function(req, res, next) {
res.cookie('XSRF-TOKEN', req.csrfToken());
next();
});
server.listen(config.get(constants.CONFIG_App_Port), function() {
log.info('App server ==> %s is listening on port %d', config.get('rest_host_config.' + config.get('app_key') + '.host'),
config.get(constants.CONFIG_App_Port));
});
//dynamically loading rest routes and socket routes from the file system
var files = routesUtils.readRoutes(true);
files.forEach(function(file) {
if (_.includes(file, 'socket')) {
commonSocketRoute = require('./../../' + file);
commonSocketRoute(socketService);
} else {
commonRoute = require('./../../' + file);
commonRoute(app);
}
});
};

我想在这里面加上羽毛,然后慢慢地开始转换。这可能吗?

是的,通过标准的@feathersjs/express框架集成,您的Feathers应用程序也将是一个完全兼容express的应用程序,它还允许注册服务。

在您的情况下,您会将var app = express();替换为:

const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
// Create an app that is a Feathers AND Express application
const app = express(feathers());
// Set up REST services (optional)
app.configure(express.rest());

一切都应该照常进行。下一步是用@feathersjs/Primus框架适配器替换自定义Primus代码:

const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const primus = require('@feathersjs/primus');
// Create an app that is a Feathers AND Express application
const app = express(feathers());
// Set up Primus with SockJS
app.configure(primus({ transformer: 'ws' }));

现在,您还可以用更简单的替换http.createServer设置

const server = app.listen(config.get(constants.CONFIG_App_Port))

由于Feathers将处理所有的Express和Primus初始化。Primus实例将作为app.primus提供。

相关内容

  • 没有找到相关文章

最新更新