partial.js logo
Latest version
v1.3.1 (RC2)

Configuration


Framework know two configuration files - debug and release. Debug configuration file is for development and release configuration file is for production. Config files are in application directory and they haven't any file extension. Configuration files are optional and they may not exist.

Directory with config files
Sample of configuration files in website directory

Structure of configuration file


Configuration files are plain text files saved in UTF-8 encoding. Structure of configuration file is very simple. Each line is a key-value value. All values in configuration file are optional. You can add your own custom values and from any place in the framework you can get the value back.

Important note:
All values obtained from the framework are readonly. Framework doesn't store back changed values into the config file. Configuration file is loaded at the start once.


How does framework parse a configuration file?

Framework reads configuration file into the memory. Then it splits all lines into the array lines.split('\n'). In the each line framework finds first colon : line.indexOf(':'). Colon is a delimiter key:value. Then framework trims white chars key.trim() from a key and it trims white chars value.trim() from a value. If the line doesn't contain colon : then line is considered as a comment.

Example:

// this is a comment
key-1                              : value
key-2                              : value

this is a comment
this is a key                      : :::: value
key-3                              : <b>value</b>
value                              : key

Result:

console.log(framework.config['key-1']);              // OUTPUT: value
console.log(framework.config['key-2']);              // OUTPUT: value
console.log(framework.config['this is a key']);      // OUTPUT: :::: value
console.log(framework.config['key-3']);              // OUTPUT: <b>value</b>
console.log(framework.config.value);                 // OUTPUT: key

The framework has built-in String.prototype for parsing configuration from string into the object String.prototype.configuration.

Framework optional options


// framework options
name                               : partialjs.com
version                            : 1.01
secret                             : secret-key-for-web
author							   : Your company name
 
etag-version                       :

// Default directory options
directory-definitions              : /definitions/
directory-contents                 : /contents/
directory-controllers              : /controllers/
directory-views                    : /views/
directory-temp                     : /tmp/
directory-templates                : /templates/
directory-resources                : /resources/
directory-public                   : /public/
directory-modules                  : /modules/
directory-logs                     : /logs/
directory-tests                    : /tests/
directory-workers                  : /workers/

// Default url for static routing
static-url                         :
static-url-js                      : /js/
static-url-css                     : /css/
static-url-image                   : /img/
static-url-video                   : /video/
static-url-font                    : /font/
static-url-upload                  : /upload/

// Default extensions for accepting files
static-accepts                     : .jpg,.png,.gif,.ico,.js,.css,.txt,.xml,.woff,.ttf,.eot,.svg,.zip,.rar,.pdf,....

// Static-accepts-custom: add your own values into the static-accepts
static-accepts-custom              : .mp3,.flv

// Default configuration of listening
// If you set IP and PORT manually in the code, then is skipped this setting.
default-ip                         : 127.0.0.1
default-port					   : 8000

// Default view layout - {directory-views}/{_layout}.html
default-layout                     : _layout
 
// Default maximum request size / length (default 5 kB)
default-request-length             : 5120
default-websocket-request-length   : 5120
 
// In milliseconds
default-request-timeout            : 3000
 
allow-gzip                         : true
 
// If you'll using Socket.io, set allow-websocket to false
allow-websocket                    : true

// enable/disable static compilation
allow-compile-js                   : true
allow-compile-css                  : true

How to get value from configuration?

In the framework class

var name = framework.config['name'];

// or

name = framework.config.name;

In the controller class

var name = controller.config['name'];

// or

name = controller.config.name;

In the view

	@{config['name']}

	<!-- OR -->

	@{config.name}


What should you know?

Configuration can be inject from URL address - Example.

configuration: @name

 
name                               : partialjs.com
 

This option is a website name and it's used in a process name. Name is inserted into the META title (in all subpages). If you want to know how the framework creates a meta information, please visit framework.onMeta().

framework.config.name
Where is used a framework.config['name']?

configuration: @author

 
author                             : Your company name
 

This option adds the meta author tag into the HTML according @{head} mark.

framework.config.author
Where is used the framework.config['author']?

configuration: @version

 
version                           : 1.01
 

This option is a website version and it's used in an etag if framework.config['etag-version'] is empty. If is the framework.config.version used as etag then all chars without a-z and 0-9 are removed. Example: 1.01 = 101.

framework.config.version
Where is used the framework.config['version']?

configuration: @etag-version

 
etag-version                      : 1
 

This option affects all etags (HTTP ETag) in static files. ETag-version value is added always at the end of generated etag. Example: framework generates etag 1760 internally and automatically add :1 to the end of etag - result 1760:1.

framework.config[etag-version]
Where is used the framework.config['etag-version']?

configuration: @secret

 
secret                          : secret-key-for-web
 

This option is a secret key for encoding & decoding values (e.g. Session). Only two methods use this value: framework.encode() and framework.decode(). For more information click here: Framework encoding & decoding hash.


configuration: @static-url and @static-url-[js, css, image, video, font, upload]

 
static-url                         :
static-url-js                      : /js/
static-url-css                     : /css/
static-url-image                   : /img/
static-url-video                   : /video/
static-url-font                    : /font/
static-url-upload                  : /upload/
 

This option affects all functions in all controllers and views. If you use e.g. controller.routeImage('logo.png') then URL will be routed into the /img/logo.png.
Crossdomain example


configuration: @static-accepts

 
static-accepts                     : .jpg,.png,.gif,.ico,.js,.css,.txt,.xml,.woff,.ttf,.eot,.svg,.zip,.rar,.pdf,....
 

framework.config['static-accepts'] is parsed as Array and this option allows/disallows request which is routed into the static file. Default accepts: .jpg, .png, .gif, .ico, .js, .css, .txt, .xml, .woff, .ttf, .eot, .svg, .zip, .rar, .pdf, .docx, .xlsx, .doc, .xls, .html, .htm, .appcache, .map, .ogg, .mp3, .webp, .swf.


configuration: @static-accepts-custom

 
static-accepts-custom              : .mp3,.flv
 

framework.config['static-accepts-custom'] is parsed as Array and then is inserted into the framework.config['static-accepts'].


Tip: automatically setting of debug / release mode

My development hostname machine is Peters.iMac.local. If I'll copy application into the server then framework is running in a production mode (config-release).

Debug & Release
How to automatically set up the debug & release mode?