PandaJS 使用说明(1.8):配置文件
配置文件的目的是把经常变化的部分提取出来,以便修改。相比 XML,直接用 js 进行配置会更为直截了当一些。
在现在的 HelloPanda 工程中有三类配置文件:
首先是 lib 和 server 的配置,在程序启动时生效,不支持热部署。
其次是特定应用的配置,修改后生效,支持热部署。
最后是用于测试的配置,与 lib 的配置相似,但设置的参数不同。
当然,现在 PandaJS 的功能还比较基础,因此需要配置的地方还不多。
接下来,我们就逐一看看这些配置文件吧。
lib 和 server 的配置文件
lib 中需要配置的有 panda.db 使用的数据库名称 和 panda.render 使用的页面文件目录(路径前缀)。
server 需要配置端口、网站根目录、web 资源文件目录等。
以下是 lib 和 server 的配置文件:
scripts/config.js
config = {
// 指定数据库名称
db : { name : 'app' },
// 指定页面文件目录(路径前缀)
render : { prefix : 'webapp/' },
// server 的配置
server : {
// 使用的端口号
port : 80,
// 网站根目录,即网站 URL 中接在域名之后的部分
contextPath: "/",
// web 资源文件目录,客户端可见的 html、css、js 等都放在这个目录下
resourceBase: "webapp",
// 上传文件的最大限制
maxUploadSize : 10 * 1024 * 1024,
// log4j 日志系统的配置文件的位置
logConfigPath: "log4j.properties",
// 服务器端执行的脚本的位置,这些脚本支持热部署
scriptsDirs : ["scripts/lib", "webapp/js/both", "scripts/app"],
// servlet 的位置 (apiServlet 和 pageServlet)
servletsDirs: ["scripts/servlets"],
// apiServlet 的访问路径映射
apiServletPath: "/api",
// pageServlet 的访问路径映射
pageServletPath: "/",
// defaultServlet(静态文件)的访问路径映射
defaultServletPath : "*.js,*.css,*.ico,*.txt,*.png,*.jpg,*.gif,*.htm,*.html,*.swf"
}
}
特定应用的配置文件
应用本身也需要配置文件,并且这些文件通常放在 app 目录或其子目录下,以支持热部署。
这里以 admin 的用户名和密码为例:
scripts/app/config.js
app.config = {
admin : { name: "admin", password: "admin123" }
};
在 api.auth 的实现中就可以使用 app.config.admin 了:
scripts/app/api/auth.js
api.auth = {
login : function(params, req) {
var admin = app.config.admin;
if (params.name !== admin.name
|| params.password !== admin.password) {
return false;
}
req.session.setAttribute("user.role", "admin");
return true;
}
}
用于测试的配置文件
测试时使用的数据库和页面文件的位置可能与生产不同,因此需要另外的配置文件。
首先,是测试 lib 的配置文件:
scripts/test/lib/config.js
config = {
db: { name: 'test' },
render: { prefix: 'scripts/test/lib/render/' }
};
此外,下一篇文章中我们将对 scripts/app 目录下的文件编写测试,现在我们可以先编写相应的配置文件:
scripts/test/app/config.js
config = {
db: { name: 'test' },
render: { prefix: 'webapp/' }
};
分享到:
相关推荐
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1155510
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1154752
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1161997
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1151963
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1159366
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1153849
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1158359
NULL 博文链接:https://xxing22657-yahoo-com-cn.iteye.com/blog/1159712
假设您已经像这样安装了 coffescript: npm install -g coffee-script将此 repo 克隆到您的计算机,然后从命令行 cd 到根目录并运行: coffee -w --output src/game --compile src/coffee这将在您处理游戏文件时...
PandaJS-按钮插件一个简单的 Button 插件,用于在PandaJS上制作快速按钮。截屏用法 this . btn = new game . Button ( {container : game . system . stage , // This is the only one required field.text : "My ...
pandaJS具有三个组件: 服务器-充当代理并存储客户端日志 客户端-将调试数据发送到服务器 管理界面-您可以在其中查看接收到的数据 客户 small footprint (仅73kb) extensible via plugins zero configuration ...
PandaJS-输入插件
一场受感染的雪 这是 ludum 敢于 31 的游戏源
devjsorg.github.io