svrx
  • Languages
  • svrx
  • svrx
    • SUMMARY
    • Contributing to svrx
    • Getting Started
    • Blog
      • Server-X: A Pluggable Platform For Local Frontend Development
    • Guide
      • API Reference
      • Option Reference
      • How To Use Routes
    • Plugins
      • How To Write A Plugin
      • How To Use Plugins
    • Practice
      • Integrations
      • Recipes
  • svrx
    • 概要
    • 贡献指南
    • 快速上手
    • Blog
      • Server-X:一款可能提升你十倍工作效率的工具
      • 使用 svrx 实现更优雅的接口 Mock
      • 说说 Server-X 的免安装插件机制
    • 进阶指南
      • API 索引
      • 参数列表
      • Routing 路由的使用
    • 插件体系
      • 如何写一个插件
      • 插件的使用
    • 项目实战
      • 结合主流脚手架使用
      • 特定场景使用
Powered by GitBook
On this page
  • root
  • svrx
  • port
  • https
  • route
  • livereload
  • serve
  • open
  • historyApiFallback
  • proxy
  • cors
  • registry
  • path

Was this helpful?

  1. svrx
  2. 进阶指南

参数列表

root

string

启动 svrx 的路径, 默认是当前工作目录。

svrx

string

你想使用的 svrx 核心包的版本。默认会使用本地安装的最新版 svrx,如果未安装过,则会安装并使用当前发布过的最新版。

port

number

端口号,默认是 8000

https

boolean

开启/关闭 https。默认是 false。

route

string

svrx --route route.js

它支持 hot-reload ,即你可以在不重启 svrx 的情况下更新路由规则

livereload

boolean, object

开启/关闭页面自动刷新功能, 默认是开启的。

livereload.exclude

string, string[]

设置文件忽略规则,如果文件符合任意匹配的 pattern,那么该文件的内容变动不会触发页面刷新。

serve

boolean, object

本地服务器配置

serve.base

string

告诉服务器从哪里提供静态文件。 默认情况下,我们会先查找当前工作目录下的文件。

你只需要在你想伺服静态资源的时候设置这个选项。

serve.index

string

访问根路径时自动展示的 index 文件的文件名,默认是index.html。

serve.directory

boolean

开启/关闭serveIndex middleware, directory默认是开启的。

访问根路径时,如果你的 index 文件不存在,serveIndex middleware可以提供一个目录中文件列表的视图,而不是返回 404。

open

boolean, string

是否在 svrx 启动后自动打开浏览器, 默认是自动打开本地地址http://localhost:${port}。

你也可以用open指定需要打开的页面:

  • false: 禁用自动打开浏览器

  • true: 同 'local'

  • 'local': 打开本地地址,如http://localhost:${port}

  • 'external': 打开外部,http://10.242.111.80:${port}/ ( 根据你的内网 IP )

  • 'home.html': 同'local/home.html' 打开 http://localhost:${port}/home.html

historyApiFallback

boolean, object

开启/关闭historyApiFallback middleware,默认是关闭的。

proxy

boolean, object, object[]

url 转发配置。 你可以在当前域名下设置proxy,将不同的 url 转发至不同的后端地址。

module.exports = {
    proxy: {
        '/api': {
            target: 'http://you.backend.server.com'  
        }
    },
}

经过如上配置后,一个/api/path请求会被转发至http://you.backend.server.com/api/path。

你也可以重写路径,就像这样:

module.exports = {
    proxy: {
        '/api': {
            target: 'http://you.backend.server.com',
            pathRewrite: {'^/api' : ''} 
        }
    },
}

现在你的/api/path请求会被转发至http://you.backend.server.com/path。

如果 target 后端的 HTTPS 服务器的证书是无效的,那么请求默认不会被接收。 你可以配置secure来改变这个默认设置:

module.exports = {
    proxy: {
        '/api': {
            target: 'https://you.https.server.com',
            secure: false 
        }
    },
}

如果你想同时把多个 path 转发到一个相同的地址,可以试试这样做:

module.exports = {
    proxy: [
        {
            context: ['/api', '/wapi', '/pub'],
            target: 'http://you.backend.server.com',
        }  
    ],
}

如果你想改变 header 中的 origin 为目标域名,可以试试将changeOrigin设为true:

module.exports = {
    proxy: {
        '/api': {
            target: 'https://you.https.server.com',
            changeOrigin: true 
        }
    },
}

cors

boolean, object

registry

string

npm源地址,设置此选项后,svrx将从此源下载插件。 默认的registry值是你工作目录下的源地址值,即npm config get registry的结果。

path

string

svrx 核心包的本地路径。仅用于开发模式下加载本地 svrx 核心包。

PreviousAPI 索引NextRouting 路由的使用

Last updated 3 years ago

Was this helpful?

指定 routing 配置文件 ,详细说明请点击

如果你的 app 使用了,那么你可能需要开启这个选项。 historyApiFallback middleware会在请求 404 后返回index.html页面。

proxy 也支持在

开启/关闭跨域资源共享()支持。 默认 Cors 是开启的。

svrx 依赖做跨域资源工程支持,更多使用方法和参数请阅读。

routing dsl 详细指南
HTML5 History API
CORS
koa2-cors
koa2-cors 参数文档
route 文件中动态配置