/velocityServer

velocity模板服务器

Primary LanguageJavaScriptMIT LicenseMIT

velocityServer

Build Status Dependency Status Coverage Status

velocity模板服务器

功能

  • velocity模板渲染
  • 静态资源服务
  • .json.json5文件支持json5语法,响应内容为json格式

安装

  1. 在velocityServer目录下运行npm install

  2. 编辑config/default.json并另存为config/local.json,配置项示例:

{
    // 服务器的运行端口
    "port": 8021,

    // 服务器根目录,请填写绝对路径
    "webapps": "",

    // velocity文件的扩展名
    "vm": [
        ".vm",
        ".html",
        ".shtml"
    ],

    // 响应头
    "responseHeaders": {
        "Cache-Control": "no-cache, no-store, must-revalidate",
        "Pragma": "no-cache",
        "Expires": "0"
    }
}

使用说明

如果模板文件同目录下有同名的js文件,则作为模板的模拟数据,例如:

index.vm

<h1>${title}</h1>
<ul>
    #foreach($item in $list)
    <li>$item</li>
    #end
</ul>
<p>Today is $now()</p>

index.js

module.exports = {
    "title": "hello title",
    "list": [
        "one",
        "two",
        "three"
    ],
    "now": function() {
        return (new Date).getDay();
    }
}

运行

node index.js

推荐使用pm2来启动velocityServer:

pm2 start index.js --name velocityServer

测试

npm test