初始化
This commit is contained in:
commit
5efd5b9c40
129 files changed
+16739
No files matched your search
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: browser-sync代理接口在IE8下返回406问题
|
||||
tags: []
|
||||
id: '64'
|
||||
categories:
|
||||
- - 分享
|
||||
date: 2016-06-28 10:15:34
|
||||
---
|
||||
|
||||
正常情况下,代理返回的头信息为: HTTP/1.1 200 OK server?? ?Apache-Coyote/1.1 content-type?? ?application/json;charset=UTF-8 transfer-encoding?? ?chunked date?? ?Tue, 28 Jun 2016 02:07:39 GMT connection?? ?close 然而在IE8下面却返回了下面的头信息: HTTP/1.1 406 Not Acceptable server: Apache-Coyote/1.1 set-cookie: JSESSIONID=7F367B9EB53FDC8306D807E0A7BD4201; Path=/; HttpOnly content-type: text/html;charset=utf-8 date: Tue, 28 Jun 2016 02:01:31 GMT connection: close Transfer-Encoding: chunked 通过对比头信息,在代理设置里做了一下判断,在低版本IE浏览器重新设置一下头信息。
|
||||
|
||||
```js
|
||||
|
||||
var browserSync = require('browser-sync');
|
||||
|
||||
var proxyMiddleware = require('http-proxy-middleware');
|
||||
|
||||
var proxy_context = ['/service/web'];
|
||||
var proxy_option = {
|
||||
target: 'http://' + proxyConfig.host + ':' + proxyConfig.port,
|
||||
//增加一个错误处理在window 7 ie7,8
|
||||
onProxyReq: function(proxyReq, req, res){
|
||||
var is4dot0 = false;
|
||||
var acceptValue = "";
|
||||
var acceptEncodeing = "";
|
||||
var rawHeaders = req.rawHeaders;
|
||||
|
||||
rawHeaders.forEach(function(value, index){
|
||||
if(value === "Accept"){
|
||||
acceptValue = rawHeaders[index+1];
|
||||
}
|
||||
if(value === "Accept-Encoding"){
|
||||
acceptEncodeing = rawHeaders[index+1];
|
||||
}
|
||||
if(value.indexOf("Mozilla/4.0") === 0){
|
||||
is4dot0 = true;
|
||||
}
|
||||
});
|
||||
if(is4dot0){
|
||||
proxyReq.setHeader("Accept", acceptValue);
|
||||
proxyReq.setHeader("Accept-Encoding", acceptEncodeing);
|
||||
}
|
||||
}
|
||||
};
|
||||
var proxy = proxyMiddleware(proxy_context, proxy_option);
|
||||
|
||||
browserSync({
|
||||
host: 'local.xxx.com',
|
||||
port: 3000,
|
||||
open: 'external',
|
||||
browser: 'google chrome',
|
||||
ghostMode: false, // 每个页面的镜像独立,不相互影响
|
||||
server: {
|
||||
baseDir: "build",
|
||||
middleware: [proxy]
|
||||
}
|
||||
});
|
||||
```
|
||||
Reference in new issue
Block a user