2017-09-05 18 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