概要
在/server/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 When upgrading to | true |
port | 使用那个TCP端口 | 3000 |
remoting | 详见Remoting properties | N/A |
restApiRoot | REST API的根URI | /api |
在应用代码里面使用app.get('property')来获取配置值。
同样你可以通过这种方式获取Express app对象的属性
。详见Express documentation的app.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的属性.
属性 | 类型 | 描述 | 默认值 |
---|---|---|---|
cors | Boolean | If false, use the CORS settings in middleware.json. | false |
context.enableHttpContext | Boolean | 详见 Using current context. | false |
errorHandler.disableStackTrace | Boolean | 设为true禁用stack traces; 会从Error object 中移除stack属性。 如果NODE_ENV 是 "production", stack traces是永久被禁用的。 | false |
json.limit | String | 最大请求主体(request body)的大小。 You can set other JSON propertis as well; see body-parser.json(). | 100kb |
json.strict | Boolean | 只解析对象和数组。 You can set other JSON propertis as well; see body-parser.json(). | false |
rest.handleErrors | Boolean | 如果为true (默认就是true),REST适配器会通过发送一个JSON格式的错误响应处理错误。如果为false, then errors are passed to the top-level application error-handler. | true |
rest.handleUnknownPaths | Boolean | 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 | true |
rest.normalizeHttpPath | Boolean | 如果为true,HTTP路径,转换:
不会作用于placeholders (例如 ":id"). 例如,"MyClass" 或者 "My_class" 转为"my-class". | false |
rest.supportedTypes | Array | 列出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' |
rest.xml | Boolean | 如果设置为true,'xm'被添加到被支持的content type中。这时如果HTTP请求头的accepts包含'xml',API会使用XML来响应。 | false |
urlencoded.extended | Boolean | 使用qs module解析extended语法。 | true |
urlencoded.limit | String | 最大请求主体。 | 100kb |
针对环境的配置
可以在下面的文件中覆盖config.json中的配置
:
config.local.js
或config.local.json
config.env.js
或config.env.json
, 这里的env
是NODE_ENV的值
(一般是development或
production
); 例如:config.production.json
.
例如:
module.exports = { host: process.env.CUSTOM_HOST, port: process.env.CUSTOM_PORT };