我有一个现有的且正常工作的羽毛项目是最新的羽毛cli("秃鹰")结构。现在我正在尝试添加 tus-node-server 作为上传服务器。正如您在链接中找到的那样,将其设置为快速中间件的说明如下:
const tus = require('tus-node-server');
const server = new tus.Server();
server.datastore = new tus.FileStore({
path: '/files'
});
var app = express();
const uploadApp = express();
uploadApp.all('*', server.handle.bind(server));
app.use('/uploads', uploadApp);
app.listen(port, host);
按照这些说明,我尝试将其添加到我的应用程序.js文件中:
// tus node server
const tus = require('tus-node-server');
const tusServer = new tus.Server();
tusServer.datastore = new tus.FileStore({
path: '../uploads'
});
const uploadApp = express();
uploadApp.all('*', tusServer.handle.bind(tusServer));
app.use('/uploads', uploadApp);
为了完整起见,我给出了整个应用程序.js文件:
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const logger = require('winston');
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');
const sequelize = require('./sequelize');
const authentication = require('./authentication');
const app = express(feathers());
// Load app configuration
app.configure(configuration());
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', express.static(app.get('public')));
// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio({
wsEngine: 'uws',
timeout: 120000
}));
app.configure(sequelize);
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
// Set up event channels (see channels.js)
app.configure(channels);
// tus node server
const tus = require('tus-node-server');
const tusServer = new tus.Server();
tusServer.datastore = new tus.FileStore({
path: '../uploads'
});
const uploadApp = express();
uploadApp.all('*', tusServer.handle.bind(tusServer));
app.use('/uploads', uploadApp);
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));
app.hooks(appHooks);
module.exports = app;
我收到此错误:
# npm start
> api_server@0.0.0 start /home/usr/api_server
> node src/
/home/usr/api_server/node_modules/@feathersjs/express/lib/index.js:11
throw new Error('@feathersjs/express requires a valid Feathers application instance');
^
Error: @feathersjs/express requires a valid Feathers application instance
at feathersExpress (/home/usr/api_server/node_modules/@feathersjs/express/lib/index.js:11:11)
at Object.<anonymous> (/home/usr/api_server/src/app.js:70:19)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/usr/api_server/src/index.js:3:13)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:617:3
应该如何设置?如何最好地将其整合到羽毛中?由此我得到的印象是,服务和钩子设置比作为中间件的设置更可取!?
作为参考,GitHub 问题的解决方案是使用require('@feathersjs/express').original
或require('express')
来初始化应用程序:
const createExpressApp = require('express');
const uploadApp = createExpressApp();
uploadApp.all('*', tusServer.handle.bind(tusServer));
app.use('/uploads', uploadApp);
或者通过访问应用程序中的require('@feathersjs/express').original(@feathersjs/express所依赖的快速模块),如下所示:
const uploadApp = express.original();
uploadApp.all('*', tusServer.handle.bind(tusServer));
app.use('/uploads', uploadApp);