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. Guide

Option Reference

root

string

Where to start svrx. Default to the current working directory.

svrx

string

The version of svrx you want to use. Default to the latest version installed locally, if not installed, it will the use the latest published version.

port

number

Specify a port number to listen for requests on, default to 8000.

https

boolean

Enable/Disable https service. Default to false.

route

string

svrx --route route.js

It supports hot-reload, which means that you can update your routing rules without restarting svrx manually.

livereload

boolean, object

Enable/Disable auto page live reload. Livereload is enabled by default.

livereload.exclude

string, string[]

Specify patterns to exclude from file watchlist. If a file matches any of the excluded patterns, the file change won’t trigger page reload.

serve

boolean, object

The set of dev server options.

serve.base

string

Tell the server where to serve static content from. By default, we'll looking for contents at the current working path.

This option is necessary only when you want to serve static files.

serve.index

string

Name of the index file to serve automatically when visiting the root location, default to index.html.

serve.directory

boolean

Enable/disable serveIndex middleware. directory is enabled by default.

When visiting the root location, if there's no index file exists, serveIndex middleware displays a view of filelist in the directory instead of a 404 page.

open

boolean, string

Enable auto opening browser after svrx started. By default, it will open http://localhost:${port} automatically.

You can also specific the opening page by setting open to:

  • true: same as 'local'

  • 'local': open local url, http://localhost:${port}

  • 'external': open external url, http://${your_ip}:${port}/

  • 'home.html': same as 'local/home.html', open http://localhost:${port}/home.html

Set open to false to disable auto open browser.

historyApiFallback

boolean, object

Enable/disable historyApiFallback middleware. It is set to false by default.

proxy

boolean, object, object[]

Proxying urls when you want to send some requests to different backend servers on the same domain.

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

Now a request to /api/path will be proxied to http://you.backend.server.com/api/path.

And you can also rewrite the path, eg:

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

Then your request to /api/path will be proxied to http://you.backend.server.com/path.

A backend server running on HTTPS with an invalid certificate will not be accepted by default. If you want to, modify your config like this:

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

If you want to proxy multiple paths to a same target, try:

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

Please note that by default, the option value of changeOrigin is true, which means svrx will always set the origin of host header to the target hostname during CORS. If you don't want this feature, just set changeOrigin to false:

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

cors

boolean, object

registry

string

Specific the npm registry where svrx should download plugins from. By default, svrx will use the registry set at your workspace, you can check with command:

npm config get registry

path

string

The local path of the svrx core package. ONLY in development mode, to load a local svrx core package.

PreviousAPI ReferenceNextHow To Use Routes

Last updated 3 years ago

Was this helpful?

Specify the configuration file of routing, see for more detail.

This option is necessary when your app is using , historyApiFallback middleware will serve a index.html page instead of 404 responses.

proxy is also supported in

Enable/disable cross-origin resource sharing(). Cors is enabled by default.

svrx makes use of package. Check out its for more advanced usages.

routing dsl guide
HTML5 History API
CORS
koa2-cors
option documentation
route configuration file