Article Source: Https://www.npmjs.com/package/ftl-server
Ftl-server is a front-end development tool that supports parsing freemarker templates, simulating backend interfaces, and reverse proxies.
Characteristics
- Parsing freemarker Templates
- Static Resource Services
- Mock request
- Proxy request
- Livereload
- Weinre
Installation
1. NPM Install Ftl-server-g
2. In the project directory, create a new configuration file, such as Ftl.config.js, under the root directory, the configuration file format is as follows:
Module.exports ={public:' E:\\somedir\\public ',//Static file directory port:' 80 ',//port number, default to hot:true,///Boolean, whether to turn on livereload, change CSS to automatically update the page style after opening, modify ftl/js/picture, etc. automatically refresh the page watch: [Require.resolve ('./page.ftl '), ' E:\\ftlserver\page.mock '],//additional configuration files that need to be monitored, values are remotedebug for the array: {// remoteDebug
configuration browser for weinre:' Firefox '}, FTL: {//config Freemarker for resolution base:' E:\\SOMEDIR\\FTL ',//configure Freemarker Template directory datafiles: [' E:\\SOMEDIR\\DATA.FTL '],//Configure the data file required by the FTL template, which is the file global: {//FTL shared data file},' FTLFILE.FTL ':function(req, res) {//key FTLFILE.FTL represents the FTL file to render, and value represents the data that renders the FTLreturn{saleactivitymap: {"000008": {activitystatus:' Actived '}}}} , mock: [{//Interface impersonation, impersonation request path:'/request ',//Request name method:' Get ',//Request method Status:' 200 ',//Request status Header: {//Request header}, Response:function(req, res) {//Requested return contentreturn{A:1, B:2 } } }, ' E:\\mock\\mock.js '],//file format see the following source code proxy: [{path:'/proxy1 ',//indicates a request to reverse proxy path target:' http://localhost:3000 '//indicates the destination address of the agent } ]}
The e:\\mock\\mock.js format is as follows:
//module.exports = [{'/mock ', ' post ', function (req, res) { return { true } }}]
Execute fs-c./ftl.config.js-p 1008 or ftl-server-c./ftl.config.js-p 1008
3. Visit the http://localhost:1008/to browse the FTL page in the directory directly.
Ftl-server of front and back end separation tools