Home > Users Guide > Configuration Directives > Ejscript Directives

Quick Nav

See Also

Ejscript Directives

The Ejscript directives control the Ejscript Web Framework and configure Ejscript web applications.

EjsAlias

Description Define an Ejscript web application
Synopsis EjsAlias UriPrefix [Directory] [Script] [Workers]
Context Default server, Virtual host, Route
Example EjsAlias /myapp/  /var/www/myapp/ start.es 10
Notes

The EjsAlias directive defines an Ejscript application at the given directory which will receive all requests that begin with specified URI prefix. This one-line directive is typically all you need to do to define an Ejscript application.

The UriPrefix argument is mandatory, all others are optional. The Directory argument is used to define the ejs HttpServer home and documents properties that describe the base directory for the ejs application and the static documents directory. This may be overridden by modifying the home and documents properties of the HttpServer instance.

The Script argument specifies the application startup script. If not startup script is specified, the following default script is used by default:

require ejs.web
let server: HttpServer = new HttpServer
var router = new Router(Router.Top)
server.on("readable", function (event, request) {
    server.serve(request, router)
})
server.listen()

The Workers arguments directive specifies the maximum number of worker threads to use when serving requests for this ejs application. Worker threads are retained in a pool for rapid reuse once requests complete. Set to zero for single-threaded operation. Defaults to any previously defined worker limit via EjsWorkers or the number of Appweb threads set via Threads (defaults to 10).

It is convenient to define applications using this directive in a separate configuration file for each application. If the application config file is stored under the Appweb "conf/apps" directory, then Appweb will read it automatically when it starts. This makes it very easy to install or remove applications by simply adding or removing an application configuration file to or from this directory.

The EjsAlias directive does the following actions:

  • Creates a new Route block for the URL prefix
  • Creates a new directory block if required for the directory
  • Creates an alias for the URL prefix to the directory
  • Defines the ejs handler as the handler for the URL prefix

Note: use a trailing "/" on the prefix to prevent matching URIs that have the prefix as part of the first (non-directory) portion of their URI.

.

EjsStartup

Description Define the Ejscript startup script
Synopsis EjsScript filename
Context Default server, Virtual host, Route
Example EjsStartup start.es EjsStartup start.es
Notes

The EjsStartup directive specifies the script filename used to start the application.

If the script filename is relative, it is found in the ejs application directory specified by EjsAlias (or Alias). Virtual hosts and location blocks will inherit an outer EjsStartup definition. If not startup script is specified, the following default script is used:

require ejs.web
let server: HttpServer = new HttpServer
var router = new Router(Router.Top)
server.on("readable", function (event, request) {
    server.serve(request, router)
})
server.listen()

EjsWorkers

Description Control if Ejscript automatically creates session objects
Synopsis EjsWorkers number
Context Default server, Virtual host, Route
Example EjsWorkers 10
Notes

This directive specifies the maximum number of worker threads to use when serving requests for the ejs handler. Worker threads are retained in a pool for rapid reuse once requests complete. Set to zero for single-threaded operation. Defaults to the number of Appweb threads set via the Threads directive (defaults to 10).

© Embedthis Software LLC, 2003-2013. All rights reserved. Embedthis, Appweb, ESP, Ejscript and Embedthis GoAhead are trademarks of Embedthis Software LLC.