create nwf application - elvinzeng/nwf GitHub Wiki

Create Project

First, update you NPLRuntime to latest version and set up environment variables for NPL.
Now, you only need to run the following command:

~ $ cd ~/workspace
~/workspace $ curl -O https://raw.githubusercontent.com/elvinzeng/nwf/master/nwf_init.sh
~/workspace $ sh ./nwf_init.sh "project-name"  

Then, this script will use parameter "project-name" to create a directoty as project root directory, it will generate the necessary directory structure and the basic file automatically.
tips: you can use git-bash to run script if you are Windows user.

Attention: Since the project auto update script will check the file changes by calculating the file checksum , If the git client is configured to automatically convert the line style will cause the project auto update script be not available. To resolve this issue, configure the git client line style conversion behavior in terminal or git-bash by executing the following command before creating or clone projects.

git config --global core.autocrlf input

directory structure

.                                --> project root directory                  
β”œβ”€β”€ module_source_repos.conf     --> module source config file
β”œβ”€β”€ dependencies.conf            --> configure all dependencies of this project
β”œβ”€β”€ reinitialize.sh              --> reinitialize project util(init all git submodulesοΌ‰
β”œβ”€β”€ npl_packages                 --> npl packages root directory
β”‚   β”œβ”€β”€ main                     --> root dir of NPL main package
β”‚   └── nwf                      --> root dir of nwf package
β”œβ”€β”€ .nwf                         --> some data generate by nwf utils
β”‚   β”œβ”€β”€ init_flag                --> a file to record initialization info
β”‚   └── md5sum                   --> checksum of file generate by framework
β”œβ”€β”€ pack.sh                      --> compress application source code to .tar.gz file
β”œβ”€β”€ restart_debug.sh             --> restart webserver(linux)
β”œβ”€β”€ shutdown.sh                  --> shutdown webserver(linux)
β”œβ”€β”€ start.sh                     --> start webserver(linux)
β”œβ”€β”€ start_win.bat                --> start webserver(Windows)
β”œβ”€β”€ start_win_auto_update.sh     --> run webserver and auto update packages(Windows)
β”œβ”€β”€ update_project.sh            --> update packages(linux and Windows)
└── www                          --> web application source code root dir.
    β”œβ”€β”€ app_initialized.lua      --> this script will run after website started
    β”œβ”€β”€ controller               --> controllers
    β”‚   β”œβ”€β”€ DemoController.lua
    β”‚   └── RootController.lua
    β”œβ”€β”€ mvc_settings.lua         --> framework init file, used as a config file.
    β”œβ”€β”€ router.lua               --> framework core module
    β”œβ”€β”€ modules                  --> root dir of nwf modules
    β”œβ”€β”€ static                   --> root dir of css,js,fonts
    β”œβ”€β”€ validator                --> validators
    β”‚   └── DemoValidator.lua
    β”œβ”€β”€ view                     --> templates
    β”‚   └── test.html
    β”œβ”€β”€ webapp.lua               --> framework core module
    └── webserver.config.xml     --> NPL WebServer config file

modify configurations

  <config>
    <string name='DEV_MODE'>debug</string>
    <table name='db'>
      <string name='host'>localhost</string>
      <string name='user_name'>postgres</string>
      <string name='user_password'>123456</string>
      <string name='database'>test</string>
      <string name='port'>5432</string>
    </table>
  </config>

Install all denpencies

First, configure dependencies module of this project.

elvin@elvin-idreamtech ~/workspace/testnwf $ cat dependencies.conf 
preload_controller_mod
helloworld

Then, execute below command to install all dependences module.

~ $ ./nwf_module_manage.sh -I

If you are not familiar with module, you could skip this step and start server directly.

Run Web Server

  • Linux: sh start.sh
  • Windows: run start_win.bat
  • Access "http://localhost:8099/ ". "it works!" means web application is start success.
⚠️ **GitHub.com Fallback** ⚠️