express - 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;
解决方案
推荐阅读
- azure - Azure DataLake (ADLS) 批量下载错误请求
- excel - 如何获取 VBA 代码以检查单元格值是否与列标题匹配并从同一行中的另一个单元格返回值?
- python - Numpy lomax 均值函数返回“inf”而不是值
- date - 如何批量比较两个日期?
- amazon-web-services - 使用 AWS CLI 查询文件夹内的文件名?
- css - 汉堡菜单不适用于样式化组件
- angular - 尝试在 Angular 6 项目中下载 PDF 时出现“失败 - 无文件”
- php - admin-ajax.php 找不到已定义的 ajax 操作
- sql - SQL 一对多关系,重复/结果作为唯一行返回
- mongodb - 从单个集合中删除 2TB 数据的更快方法(无需分片)