我有下一个快速服务器,我想将重定向.js文件重定向到相应的.js.gz文件,但是当我请求/static/common.js不重定向时
响应标头
HTTP / 1.1 200好的 X-Powered-By:快递 Accept-Ranges:字节 Cache-Control:public,max-age = 0 最后修改时间:2017年3月29日星期三格林威治标准时间14:30:17 ETag:W /" 2b4084-15b1a796ca8" 内容类型:应用程序/ javascript 内容长度:2834564 日期:2017年3月29日星期三16:25:53 GMT 连接:保持活力
// define the folder that will be used for static assets
const staticFolder = './';
app.use(favicon(`${staticFolder}/icons/favicon.ico`));
app.use('/static', Express.static(staticFolder));
app.use('/', Express.static(`${staticFolder}/sw`));
app.use(locale(supported));
app.get('*.js', (req, res, next) => {
const reqI = req;
reqI.url += '.gz';
res.set('Content-Encoding', 'gzip');
next();
});
// universal routing and rendering
app.get('*', (req, res) => {
我正在使用下一个配置的docker镜像中使用nginx:
server {
listen 80;
server_name api.inmoblex.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name api.inmoblex.com;
charset utf-8;
ssl_certificate /www/certs/fullchain.pem;
ssl_certificate_key /www/certs/privkey.pem;
location / {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80 default_server;
server_name inmoblex.com www.inmoblex.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2 default_server;
server_name inmoblex.com www.inmoblex.com;
charset utf-8;
ssl_certificate /www/certs/fullchain.pem;
ssl_certificate_key /www/certs/privkey.pem;
location / {
proxy_pass http://node:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
答案 0 :(得分:1)
不需要预压缩或重定向。
import StoreKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let shortestTime: UInt32 = 50
let longestTime: UInt32 = 500
guard let timeInterval = TimeInterval(exactly: arc4random_uniform(longestTime - shortestTime) + shortestTime) else { return true }
Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(AppDelegate.requestReview), userInfo: nil, repeats: false)
}
@objc func requestReview() {
SKStoreReviewController.requestReview()
}
答案 1 :(得分:1)
在这种情况下,我的错误是中间件永远不会运行,因为.js文件由静态中间件提供。
我在使用压缩包之前解决了这个问题,因为我在静态中间件之后使用了这个。
import { Server } from 'http';
import Express from 'express';
import React from 'react';
import locale from 'locale';
import { sync as globSync } from 'glob';
import { renderToString } from 'react-dom/server';
import match from 'react-router/es6/match';
import RouterContext from 'react-router/es6/RouterContext';
import UAParser from 'ua-parser-js';
import { Provider } from 'react-redux';
import { Map } from 'immutable';
import favicon from 'serve-favicon';
import * as path from 'path';
import { readFileSync } from 'fs';
import { IntlProvider } from 'react-intl';
import routes from './routes';
import NotFoundPage from './components/NotFoundPage';
import configureStore from './stores';
import WithStylesContext from './WithStylesContext';
const compression = require('compression');
const supported = ['es', 'en'];
// initialize the server and configure support for ejs templates
const app = new Express();
const server = new Server(app);
// define the folder that will be used for static assets
const staticFolder = './';
app.use(compression());
app.use(favicon(`${staticFolder}/icons/favicon.ico`));
app.use('/static', Express.static(staticFolder));
app.use('/', Express.static(`${staticFolder}/sw`));
app.use(locale(supported));