首页 > 解决方案 > FeathersJS 加载静态内容很慢

问题描述

Feathers/Express 加载静态内容真的很慢。有什么方法可以在不使用 Nginx 的情况下加快速度?对于一个 200-300kb 的文件,在 ADSL 连接上以 20mbps 的下载速度加载图像的每个请求大约需要 3 秒。我试过重新订购中间件,但没有运气,我真的无话可说,但我的帖子主要是代码。

我的 App.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 hbs = require('hbs');

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 authentication = require('./authentication');

const mongodb = require('./mongodb');

require('dotenv').config();

const app = express(feathers());

// Load app configuration
app.configure(configuration());

// Host the public folder
app.use('/', express.static(app.get('public'), { maxAge: '30d' }));

// 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')));

// Set template engine
app.set('view engine', 'hbs');

// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());

app.configure(mongodb);

// 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);

// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));

app.hooks(appHooks);

module.exports = app;

标签: expressfeathersjs

解决方案


推荐阅读