thymol-node-server

1.0.0-pre.8 • Public • Published

Thymol Node Server

A nodejs based server-side JavaScript Thymeleaf template engine built on Thymol and Express.

This is an experimental web server that processes server-side Thymeleaf templates, JavaScript and data using Thymol and returns documents rendered as HTML.

Pre-Requisites

You will need nodejs and npm (node comes with npm now). This project depends on the Thymol Node module see npmjs and github.

Installation

Either "npm install thymol-node-server -g"

Or clone the project from github and "npm install" it (locally).

Execution

If you globally installed with npm all you need to do is:

thymol [-w <path-to-webapp-script>] [-c <path-to-config-file>] <path-to-webapp-root> [<relative-path-to-templates>]

If you're using a git clone:

Then on *nix simply run:

 bin/thymol-server [-w <path-to-webapp-script>] [-c <path-to-config-file>] <path-to-webapp-root> [<relative-path-to-templates>]

On Windows run this file using the nodejs node command:

node bin/thymol-server [-w <path-to-webapp-script>] [-c <path-to-config-file>] <path-to-webapp-root> [<relative-path-to-templates>]

Where:

"<path-to-webapp-script>" is the (optional) path locating the script that loads and intialises the web application code.

"<path-to-config-file>" is the (optional) path locating the configuration file (see below).

"<path-to-webapp-root>" identifies the base directory of your web application (the webapp root directory).

"[<relative-path-to-templates>]" is the (optional) relative path from the webapp root directory to the template directory.

References to resource files should be relative to the webapp root directory.

Configuration

Thymol Node Server is configured using a simple JavaScript file. The default configuration file is loaded from "config/server-config.js".

You can edit this file or nominate an alternative using the "-c " option on the server start-up command line.

You can use the configuration file to set the values of Thymol control parameters (see). The configuration file can also be used to set web server control parameters (server host name, port etc).

For example, the values for webapp root and template path can be specified in the configuration file so that they don't have to be specified on the command line.

There are two control parameters specific to Thymol Node Server:

dataThymolLoading: this is a boolean control, if set to "true", the server will load and execute any JavaScript files that are specified in "data-thymol-load" attributes of <script> tags in templates as they are processed.
                   The value of this control defaults to "false", so "data-thymol-load" scripts are ignored by default.
 
resetPerRequest: this is a boolean control, if set to "true", the server will reset all internal configuration on receipt of every new request. (This is used by Thymol automated integration tests). 

You can also use the configuration file to "fine tune" the jQuery configuration using the jQueryConfiguration initialiser (properties of this object are set on jQuery instances).

For example using:

jQueryConfiguration: {
  support: {
    cors: true
  }
}

Will set the "support.cors" property of jQuery instances to "true" (you may need to do this if you're using jQuery 1.x.x).

Operation

The thymol-server will process templates rooted at the specified webapp-root value.

The server follows the same syntax and applies the same rules as client-side Thymol except that JavaScript files defined by the "src" attributes of <script> tags are ignored.

JavaScript files defined by "data-thymol-load" attributes in <script> tags will also be ignored unless the "dataThymolLoading" configuration option is set to "true".

Examples

The following 2 examples illustrate some familiar static demonstration cases.

a). Download the 2.X-master branch from thymol.js and start the server with the sourceforge/Webcontent sub-directory as the webapp root directory:

thymol <installation-path>/thymol/sourceforge/Webcontent

Then browse to http://localhost:3000/examples. Most of these examples should work correctly with the exception of "say hello (split)" and "session" that depend on client-side only features.

b). Clone the Thymol petclinic example project and start the server with "petclinic.js" as the web application code file, the src/main/webapp sub-directory as the webapp root directory and "/WEB-INF/thymeleaf" as the template path:

thymol -w <installation-path>/src/main/webapp/resources/thymol/petclinic.js  <installation-path>/src/main/webapp /WEB-INF/thymeleaf

Where <installation-path> is the fully qualified path to the project installation directory (including "thymol.thymeleafexamples-petclinic").

Once the server has started, browse to http://localhost:3000/welcome - you should see the well known petclinic home page.

Most of the remaining petclinic site pages will not work correctly until the back-end database has been set up correctly. For instructions on how this is done please see here.

Issues/Support

For bug reports/enhancement requests use the issues link here.

For support or further information, please post a question on the Thymol users forum.

Package Sidebar

Install

npm i thymol-node-server

Weekly Downloads

1

Version

1.0.0-pre.8

License

Apache 2.0

Last publish

Collaborators

  • thymoljs.org