2017-09-05 86 views
0

精簡版服務器似乎被忽略了我的企圖覆蓋默認的指數。這是得到精簡版服務器來識別BS-config.js的「server.index」覆蓋的正確方法?

我有BS-config.json:

{ 
    "server": { 
    "baseDir": "src", 
    "index": "/index.3.html", 
    "routes": { 
     "/node_modules": "node_modules" 
    } 
    } 
} 

我使用的精簡版,服務器版2.3.0,就像這樣:

> lite-server -c=bs-config.json 

browser-sync config ** 

{ injectChanges: false, 
    files: [ './**/*.{html,htm,css,js}' ], 
    watchOptions: { ignored: 'node_modules' }, 
    server: 
    { baseDir: 'src', 
    middleware: [ [Function], [Function] ], 
    directory: true, 
    index: '/index.3.html', 
    routes: { '/node_modules': 'node_modules' 
    } 
    } 
} 

在上面的控制檯日誌輸出,它承認「index.3.html」,然而,當瀏覽器請求「GET http://localhost」的BS-config.json指數默認情況下,控制檯顯示它正試圖以服務代替的index.html index.3.html。

[Browsersync] Serving files from: src 
[Browsersync] Watching files... 
17.09.04 22:35:51 404 GET /index.html 

我也試圖提供BS-config.js:

"use strict"; 

module.exports = { 
    "server": { 
    "baseDir": "src", 
    index: "i/index.3.html", 
    "directory":true, 
    "routes": { 
     "/node_modules": "node_modules" 
    } 
    // middleware,: { 
    // // overrides the second middleware default with new settings 
    // 1: require('connect-history-api-fallback')({index: '/index.3.html', verbose: true}) 
    // } 
    } 
} 

,並與運行精簡版服務器:

> lite-server -c=bs-config.js 

但行爲是一樣的。

問:我怎麼重寫BS-配置的server.index爲精簡版服務器?

回答

0

精簡版的服務器的配置,default.js套在它的指數第二中間件「後退」功能。這似乎是overring bs-config設置。

所以溶液似乎是,重寫中間件根據需要來設置的索引。

BS-config.js:

module.exports = { 
    "server": { 
    "baseDir": "src", 
    "routes": { 
     "/node_modules": "node_modules" 
    }, 
    middleware: { 
     // overrides the second middleware default with new settings 
     1: require('connect-history-api-fallback')({ 
      index: '/index.3.html', 
      htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] // systemjs workaround}) 
    } 
    } 
} 

注: 1.如果精簡版服務器的未來版本中改變它的默認配置的中間件把指數回落的中間件功能的不同的索引位置數組,或者設置不同的響應頭,那麼這個bs-config解決方案將需要相應地改變。

引用: Browserync文檔:https://browsersync.io/docs/options

精簡版服務器:https://github.com/johnpapa/lite-server