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

FrameworkController


FrameworkController is created after is validate a route. The framework knows two types of controller: HTTP/HTTPS Controller and WebSocket Controller. For more informations about controllers click on How do controllers work?.


IMPORTANT MARKUPS: http is for HTTP/HTTPS requests and WebSocket is for WebSocket connections. Some methods and properties support both options.

Properties


controller.async {Async}controller.cache {FrameworkCache}controller.config {FrameworkConfig}controller.connections {Object}controller.files {HttpFile Array}controller.flags {String Array}controller.framework {Framework}controller.fs {FrameworkFileSystem}controller.get {Object}controller.global {Object}controller.ip {String}controller.isConnected {Boolean}controller.isDebug {Boolean}controller.isProxy {Boolean}controller.isSecure {Boolean}controller.isTest {Boolean}controller.name {String}controller.online {Number}controller.path {FrameworkPath}controller.post {Object}controller.prefix {String}controller.repository {Object}controller.req {Object}controller.res {Object}controller.session {Object}controller.sseID {String}controller.status {Number}controller.subdomain {String Array}controller.uri {Object}controller.url {String}controller.user {Object}controller.xhr {Boolean}
controller.async;
httpwebsocket
return Async;

Async class for async work.

controller.cache;
readonlyhttpwebsocket
return FrameworkCache;

Return the framework cache object.

controller.config;
readonlyhttpwebsocket

Return the framework config.

controller.connections;Default: {}
readonlywebsocket
return Object;

All connection of users.

controller.files;Default: []
readonlyhttp

Parsed files from a request content.

controller.flags;Default: []
readonlyhttp
return String Array;

Get all route flags.

controller.framework;
readonlyhttpwebsocket
return Framework;

Return the framework object.

controller.fs;
readonlyhttpwebsocket
return FrameworkFileSystem;

return file system for dynamic manipulating web application files.

controller.get;Default: {}
readonlyhttp
return Object;

Parsed data from URL params.

controller.global;Default: {}
httpwebsocket
return Object;

Get the framework global variables.

controller.ip;
readonlyhttp
return String;

Current HTTP host address.

controller.isConnected;
readonlyhttp
return Boolean;

Is a request connected?

controller.isDebug;
readonlyhttpwebsocket
return Boolean;

Is debug mode?

controller.isProxy;
readonlyhttp
return Boolean;

Is partial.js proxy request?

controller.isSecure;Default: false
importanthttpwebsocket
return Boolean;

Is secured request?

controller.isTest;
readonlyhttp
return Boolean;

Is assertion testing of request?

controller.name;
readonlyhttpwebsocket
return String;

Return name of controller.

controller.online;Default: 0
readonlywebsocket
return Number;

Online user count (websocket).

controller.path;
readonlyhttpwebsocket
return FrameworkPath;

Return path object for getting all framework paths.

controller.post;Default: {}
readonlyhttp
return Object;

Parsed data from a request content.

controller.prefix;Default: ''
readonlyhttp
return String;

Current prefix (framework.onPrefix).

controller.repository;Default: {}
importanthttpwebsocket
return Object;

Controller repository object for storing current request values.

controller.req;
readonlyhttp
return Object;

Current HTTP request.

controller.res;
readonlyhttp
return Object;

Current HTTP response.

controller.session;Default: null
httpwebsocket
return Object;

Current HTTP session.

controller.sseID;Default: ''
readonlyhttp
return String;

Get lastEventID for Server Sent Events.

controller.status;Default: 200
http
return Number;

Gets / Sets status code of response.

controller.subdomain;
readonlyhttp
return String Array;

Current subdomain.

controller.uri;
readonlyhttp
return Object;

Current URI object.

controller.url;
readonlyhttpwebsocket
return String;

Current relative URL address without params and hash tags.

controller.user;Default: null
httpwebsocket
return Object;

Current HTTP user.

controller.xhr;
readonlyhttp
return Boolean;

Check if request is XMLHttpRequest.

Methods


controller.all(fn)controller.await(name, fn)controller.baa([name])controller.binary(buffer, contentType)controller.cancel {FrameworkController}controller.clear()controller.close([names])controller.complete([callback])controller.content(name, [isPartial])controller.cors(allow, [method], [header], [credentials])controller.currentContent(path)controller.currentCSS(path)controller.currentDownload(path)controller.currentImage(path)controller.currentJS(path)controller.currentTemplate(path)controller.currentVideo(path)controller.currentView(path)controller.custom()controller.database(name)controller.destroy()controller.empty([headers])controller.error(err)controller.file(filename, [downloadName], [headers])controller.fileAsync(filename, [downloadName], [headers])controller.find(id)controller.functions(name)controller.head(value)controller.header(name, value)controller.host([path])controller.image(filename, fnProcess, [headers], [useImageMagick])controller.json(obj, [headers])controller.jsonAsync(obj, [headers])controller.layout(name)controller.log([param..1], [param..2], [param..n])controller.meta(title, [description], [keywords])controller.mmr(filename, [stream], [cb])controller.models(name)controller.module(name)controller.noClear([enable])controller.notModified([compare], [strict])controller.pipe(url, [headers], [callback])controller.plain(contentBody, [headers])controller.proxy(url, [obj], fnCallback, [timeout])controller.redirect(url, [permament])controller.redirectAsync(url, [permament])controller.resource([name], key)controller.routeCSS(name)controller.routeFont(name)controller.routeImage(name)controller.routeJS(name)controller.routeStatic(name)controller.routeUpload(name)controller.routeVideo(name)controller.run([callback])controller.send(message, [id], [blacklist])controller.setExpires(value)controller.setModified(value)controller.settings([param..1], [param..2], [param..n])controller.sitemap(name, url, [index])controller.sse(data, [name], [id], [retry])controller.stream(contentType, stream, [downloadName], [headers])controller.template(name, model, [nameEmpty], [repository])controller.validate(model, properties, [prefix], [name])controller.view(name, [model], [headers], [isPartial])controller.view401()controller.view403()controller.view404()controller.view500(err)controller.view501()controller.viewAsync(name, [model], [headers])controller.wait(name, [waitingFor], fn)
controller.all(fn);
importantWebSocket
return FrameworkController;

Get each client connection.

controller.await(name, fn);
httpwebsocket
return FrameworkController;

Add a function to async list.

controller.baa([name]);
http
return Object;

Basic access authentication (baa). Return object with user and password. If baa return null then function close a response (and sent authentification).

controller.binary(buffer, contentType);
http
return FrameworkController;

Binary response.

controller.cancel;
http
return FrameworkController;

Cancel executing controller.

controller.clear();
http
return FrameworkController;

Clear uploaded files. Important: for prevent auto clearing use controller.noClear().

controller.close([names]);
httpwebsocket
return FrameworkController;

Close a response (controller.mmr() or controller.sse() or by the custom response flushing). In the WebSocket close all connections or specific connection (by the names).

controller.complete([callback]);
httpwebsocket
return FrameworkController;

Run async functions.

controller.content(name, [isPartial]);
importanthttp
return FrameworkController;

Response custom content.

controller.cors(allow, [method], [header], [credentials]);
http
return Boolean;

Cross-origin resource sharing.

controller.currentContent(path);
http
return FrameworkController;

Set current path to contents folder.

controller.currentCSS(path);
http
return FrameworkController;

Set current path to CSS.

controller.currentDownload(path);
http
return FrameworkController;

Set current path to download folder.

controller.currentImage(path);
http
return FrameworkController;

Set current path to image.

controller.currentJS(path);
http
return FrameworkController;

Set current path to JS.

controller.currentTemplate(path);
http
return FrameworkController;

Set current path to templates folder.

controller.currentVideo(path);
http
return FrameworkController;

Set current path to video.

controller.currentView(path);
http
return FrameworkController;

Set current path to views folder.

controller.custom();
httponetime
return Boolean;

Set custom responses.

controller.database(name);
httpwebsocket

Return a database object. This function is alias for framework.database().

controller.destroy();
httpwebsocket
return FrameworkController;

HTTP == destroy a request, WebSocket == destroy all conections.

controller.empty([headers]);
importanthttp
return FrameworkController;

Response empty content (text/plain).

controller.error(err);
httpwebsocket
return FrameworkController;

Mark an error.

controller.file(filename, [downloadName], [headers]);
importanthttp
return FrameworkController;

Response file. For load file from anywhere - file name must start with ~ char.

controller.fileAsync(filename, [downloadName], [headers]);
importanthttp
return FrameworkController;

Response file (Async). For load file from anywhere - file name must start with ~ char. This method is called when all operation in async (controller.await(), controller.wait()) are completed.

controller.find(id);
importantWebSocket

Find client connection.

controller.functions(name);
httpwebsocket
return Object;

Return a controller functions.

controller.head(value);
http
return String;

Append TAG to HTML head. The function supports append more string arguments. If function haven't arguments then return stored values as one string.

controller.header(name, value);
http
return FrameworkController;

Set response header.

controller.host([path]);
http
return String;

Get host name.

controller.image(filename, fnProcess, [headers], [useImageMagick]);
importanthttp
return FrameworkController;

Response image. For load file from anywhere - file name must start with ~ char.

controller.json(obj, [headers]);
importanthttp
return FrameworkController;

Response JSON.

controller.jsonAsync(obj, [headers]);
importanthttp
return FrameworkController;

Response JSON (async). This method is called when all operation in async (controller.await(), controller.wait()) are completed.

controller.layout(name);
http
return FrameworkController;

Set layout for current view.

controller.log([param..1], [param..2], [param..n]);
httpwebsocket
return FrameworkController;

Append to log file.

controller.meta(title, [description], [keywords]);
http
return FrameworkController;

Create a meta tags.

controller.mmr(filename, [stream], [cb]);
http
return FrameworkController;

Send a file or stream via [m]ultipart/x-[m]ixed-[r]eplace.

controller.models(name);
httpwebsocket
return Object;

Return a controller models.

controller.module(name);
httpwebsocket
return FrameworkController;

Return a module object.

controller.noClear([enable]);
http
return FrameworkController;

Enable/Disable auto clearing of uploaded files. For manual clearing of uploaded files use: controller.clear().

controller.notModified([compare], [strict]);
http
return Boolean;

Check if ETag or Last Modified has modified. If @compare === {String} compare if-none-match .... if @compare === {Date} compare if-modified-since. This function automatically flush a response 304 (if not modified). If content is not modified then return true.

controller.pipe(url, [headers], [callback]);
importanthttp
return FrameworkController;

Create response from URL (copy response to a response without headers).

controller.plain(contentBody, [headers]);
importanthttp
return FrameworkController;

Response plain text (text/plain).

controller.proxy(url, [obj], fnCallback, [timeout]);
http
return FrameworkController;

Proxy request to other partial.js website.

controller.redirect(url, [permament]);
importanthttp
return FrameworkController;

Response redirect.

controller.redirectAsync(url, [permament]);
importanthttp
return FrameworkController;

Response redirect (async). This method is called when all operation in async (controller.await(), controller.wait()) are completed.

controller.resource([name], key);
httpwebsocket
return String;

Read from resource file.

controller.routeCSS(name);
http
return String;

Route a CSS file by the config['static-url-css']. Returns relative URL address.

controller.routeFont(name);
http
return String;

Route a font file by the config['static-url-font']. Returns relative URL address.

controller.routeImage(name);
http
return String;

Route a image file by the config['static-url-image']. Returns relative URL address.

controller.routeJS(name);
http
return String;

Route a JS file by the config['static-url-js']. Returns relative URL address.

controller.routeStatic(name);
http
return String;

Route a static file by the config['static-url']. Returns relative URL address.

controller.routeUpload(name);
http
return String;

Route a upload file by the config['static-url-upload']. Returns relative URL address.

controller.routeVideo(name);
http
return String;

Route a video file by the config['static-url-video']. Returns relative URL address.

controller.run([callback]);
httpwebsocket
return FrameworkController;

Run async functions. This function is same as controller.complete().

controller.send(message, [id], [blacklist]);
importantWebSocket
return FrameworkController;

Send message via websocket to online users. Message will be sended to all connections or specific connection.

controller.setExpires(value);
http
return FrameworkController;

Set expires header

controller.setModified(value);
http
return FrameworkController;

Set last modified header or Etag

controller.settings([param..1], [param..2], [param..n]);
http
return FrameworkController;

Create a custom setting for views.

controller.sitemap(name, url, [index]);
http
return FrameworkController;

Add URL to sitemap.

controller.sse(data, [name], [id], [retry]);
http
return FrameworkController;

Send data via [S]erver-[s]ent [e]vents.

controller.stream(contentType, stream, [downloadName], [headers]);
importanthttp
return FrameworkController;

Response stream.

controller.template(name, model, [nameEmpty], [repository]);
http
return String;

Render template into the string. If model is empty and nameEmpty is not defined then function return empty string.

controller.validate(model, properties, [prefix], [name]);
httpwebsocket
return Boolean;

Validate an object model.
IMPORTANT: If 'properties' is string then properties read by the schema validation. Read more in Builders.SchemaBuilder.

controller.view(name, [model], [headers], [isPartial]);
importanthttp
return FrameworkController or String;

Response a view. IMPORTANT: view is loaded by the controller name. Example: my-controller-name.js set view path to /views/my-controller-name/some-view.html - except default.js of controller name. If your view name starts with ~ then will skipped a controller directory name.

controller.view401();
importanthttp
return FrameworkController;

Response 401 error - Unauthorized.

controller.view403();
importanthttp
return FrameworkController;

Response 403 error - Forbidden.

controller.view404();
importanthttp
return FrameworkController;

Response 404 error - Not Found.

controller.view500(err);
importanthttp
return FrameworkController;

Response 500 error - Internal server error.

controller.view501();
importanthttp
return FrameworkController;

Response 501 error - Not Implemented.

controller.viewAsync(name, [model], [headers]);
importanthttp
return FrameworkController or String;

Response a view. IMPORTANT: view is loaded by the controller name. Example: my-controller-name.js set view path to /views/my-controller-name/some-view.html - except default.js of controller name. If your view name starts with ~ then will skipped a controller directory name. This method is called when all operation in async (controller.await(), controller.wait()) are completed.

controller.wait(name, [waitingFor], fn);
httpwebsocket
return FrameworkController;

Add a function to async waiting list.

Delegates


exports.request()exports.usage(detailed)
exports.request();

Delegate for capture each request into this controller.

exports.usage(detailed);
must return String
return String;

Controller monitoring.

Events


controller.on('close', client)controller.on('destroy', )controller.on('error', err, client)controller.on('message', client, message)controller.on('open', client)controller.on('send', message, id, blacklist)
controller.on('close', function(client) {    // YOUR CODE HERE});
websocket

This event is triggered when is user disconnect.

controller.on('destroy', function() {    // YOUR CODE HERE});
websocket

This event is triggered when is WebSocket destroyed.

controller.on('error', function(err, client) {    // YOUR CODE HERE});
websocket

This event is triggered when is error.

controller.on('message', function(client, message) {    // YOUR CODE HERE});
websocket

This event is triggered when recieved a message.

controller.on('open', function(client) {    // YOUR CODE HERE});
websocket

This event is triggered when is user connected.

controller.on('send', function(message, id, blacklist) {    // YOUR CODE HERE});
websocket

This event is triggered when is sended a message.