概要

在/server/config.json文件中定义应用服务端的配置。下面是默认的一些配置:

config.json
{
  "restApiRoot": "/api",
  "host": "0.0.0.0",
  "port": 3000,
  "remoting": {
    ... // See below
  },
  "legacyExplorer": false
}

顶级属性

下面的表列出了你可以对哪些属性觉醒配置。

属性描述默认值

aclErrorStatus

当一个验证用户因为ACL被拒绝进入,默认会返回一个http 401 unauthorized 的状态码。如果你想使用403,那么你可以通过配置这个属性来达到。这个值是必填的,例如,当使用AngularJS拦截器来区分是现实一个登陆页还是现实一个请求被拒绝。

可以在Model definition JSON file 中为没个模型定义不同的值。

401
host

Node HTTP服务的主机或者IP地址。如果请求一个不同的主机或者IP地址,应用不会接受连接。详见server.listen()

localhost
legacyExplorer

Set to false to disable old routes /models and /routes that are exposed, but no longer used by API Explorer; use true or omit the option to keep them enabled.

When upgrading to v2.14.0, set "legacyExplorer": false

true
port使用那个TCP端口3000
remoting详见Remoting propertiesN/A
restApiRootREST API的根URI/api

在应用代码里面使用app.get('property')来获取配置值。

同样你可以通过这种方式获取Express app对象的属性。详见Express documentationapp.get()

Remoting属性

Properties under the remoting top-level property 这个属性决定了应用通过strong-remoting如果执行一个远程操作;例如:

...
"remoting": {
    "context": {
      "enableHttpContext": false
    },
    "rest": {
      "normalizeHttpPath": false,
      "xml": false, 
      "handleErrors" : true,
      "handleUnknownPaths" : true
    },
    "json": {
      "strict": false,
      "limit": "100kb"
    },
    "urlencoded": {
      "extended": true,
      "limit": "100kb"
    },
    "cors": false,
    "errorHandler": {
      "disableStackTrace": false
    }
}

下面的表描述了remoting的属性.

Icon

下面的属性前缀都是 "remoting",例如:remoting.json.limit。

属性类型描述默认值
corsBooleanIf false, use the CORS settings in middleware.json.false
context.enableHttpContextBoolean详见 Using current context.false
errorHandler.disableStackTraceBoolean

设为true禁用stack traces; 会从Error object 中移除stack属性。

如果NODE_ENV 是 "production", stack traces是永久被禁用的。

false
json.limitString

最大请求主体(request body)的大小。

You can set other JSON propertis as well; see body-parser.json().

100kb
json.strictBoolean

只解析对象和数组。

You can set other JSON propertis as well; see body-parser.json().

false
rest.handleErrorsBoolean如果为true (默认就是true),REST适配器会通过发送一个JSON格式的错误响应处理错误。如果为false, then errors are passed to the top-level application error-handler.true
rest.handleUnknownPathsBoolean

If true (the default), then the REST adapter emits a 404 error for unknown paths. The REST error handler or the application error handler then handle this error; rest.handleErrors above.

If false, then the REST adapter delegates handling unknown paths to the top-level application by calling next().

true
rest.normalizeHttpPathBoolean

如果为true,HTTP路径,转换:

  • 大写转为小写
  • 下划线(_)转为中划线 (-)
  • CamelCase转为用中划线 (-)分开

不会作用于placeholders (例如 ":id").

例如,"MyClass" 或者 "My_class" 转为"my-class".

false
rest.supportedTypesArray

列出HTTP响应支持的content type。

The response type will match that specfied in the HTTP request "accepts" header, if it is in this list of supported types.

如果设置了这个属性,rest.xml的设置会被忽略。

注意: 'application/vnd.api+json' 是被支持的,但是它不是一个默认的type。

'application/json'
'application/javascript'
'application/xml'
'text/javascript'
'text/xml'
'json'
'xml'

rest.xmlBoolean

如果设置为true,'xm'被添加到被支持的content type中。这时如果HTTP请求头的accepts包含'xml',API会使用XML来响应。

false
urlencoded.extendedBoolean

使用qs module解析extended语法。

详见 bodyParser.urlencoded().

true
urlencoded.limitString

最大请求主体。

详见 bodyParser.urlencoded().

100kb

针对环境的配置

可以在下面的文件中覆盖config.json中的配置:

  • config.local.js 或 config.local.json
  • config.env.js 或 config.env.json, 这里的env 是NODE_ENV的值 (一般是developmentproduction); 例如:config.production.json.
Icon

这些文件只能使用值类型(字符串,数字)来覆盖顶层的属性。目前还不支持聚合对象和数组。

例如:

config.production.js
module.exports = {
  host: process.env.CUSTOM_HOST,
  port: process.env.CUSTOM_PORT
};
详见Environment-specific configuration