Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appix

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appix - npm Package Compare versions

Comparing version 1.0.0-alpha-02 to 1.0.0-alpha-03

26

framework/bootstrap.js

@@ -24,18 +24,16 @@ 'use strict';

* @example
* 'use strict';
* let di = require('appix');
* let Bootstrap = di.load('@{appix}/bootstrap');
* // bootstrap application
* let easyInit = new Bootstrap({
* 'use strict';
* let di = require('appix');
* let Bootstrap = di.load('@{appix}/bootstrap');
* // bootstrap application
* let easyInit = new Bootstrap({
* listenPort: 9500,
* appPath: __dirname + '/app'
* }, function dynamicComponentConfig(components) {
* }, function dynamicComponentConfig(components) {
* components.set('my-component', {});
* });
* });
*
* di.setInstance('en-demo', easyInit);
*
* let router = easyInit.getComponent('appix/router');
*
* router.add([
* di.setInstance('en-demo', easyInit);
* let router = easyInit.getComponent('appix/router');
* router.add([
* {

@@ -49,5 +47,5 @@ * url: '/',

* }
* ]);
* ]);
*
* easyInit.listen();
* easyInit.listen();
*/

@@ -54,0 +52,0 @@ class Bootstrap extends Type {

@@ -20,9 +20,23 @@ 'use strict';

* @example
* let logger = new Logger();
* logger.info('My message', dataObject);
* logger.error('My message', dataObject);
* logger.warn('My message', dataObject);
* logger.trace('My message', dataObject);
* logger.fatal('My message', dataObject);
* logger.debug('My message', dataObject);
* // env.json
* {
* "components": {
* "appix/logger": {
* "enabled": true,
* "console": true,
* "level": 30
* }
* }
* }
* class User extends Controller {
* beforeEach() {
* let logger = this.getComponent('appix/logger');
* logger.info('My message', dataObject);
* logger.error('My message', dataObject);
* logger.warn('My message', dataObject);
* logger.trace('My message', dataObject);
* logger.fatal('My message', dataObject);
* logger.debug('My message', dataObject);
* }
* }
*/

@@ -29,0 +43,0 @@ class Logger extends Type {

@@ -19,2 +19,47 @@ 'use strict';

* Router handles routing for application.
* All routes should be added during bootstrap process
* @example
* 'use strict';
* let di = require('appix');
* let Bootstrap = di.load('@{appix}/bootstrap');
* // bootstrap application
* let easyInit = new Bootstrap({
* listenPort: 9500,
* appPath: __dirname + '/'
* });
*
* di.setInstance('en-demo', easyInit);
* let router = easyInit.getComponent('appix/router');
* router.add([
* {
* url: '/',
* route: 'app/Index'
* },
* {
* url: '/forward',
* route: 'app/Forward'
* },
* {
* url: '/test',
* route: 'app/Test'
* },
* {
* url: '/test-pall',
* route: 'app/TestPall'
* },
* {
* url: '/goto301',
* route: 'app/Redirect301'
* },
* {
* url: '/goto',
* route: 'app/Redirect'
* },
* {
* url: '/favicon.ico',
* route: 'app/Favicon'
* }
* ]);
*
* easyInit.listen();
*/

@@ -21,0 +66,0 @@ class Router extends Type {

@@ -6,2 +6,3 @@ 'use strict';

let http = di.load('http');
let logger;
/**

@@ -20,6 +21,7 @@ * @license Mit Licence 2015

class Server extends Type {
constructor() {
constructor(config, bootstrap) {
super({
server: Type.OBJECT
});
logger = bootstrap.getComponent('appix/logger');
this.server = http.createServer();

@@ -87,9 +89,17 @@ }

this.on('request', (request, response) => {
di.setAlias('controllersPath', bootstrap.defaults.controllersPath);
di.setAlias('modulesPath', bootstrap.defaults.modulesPath);
let nRequest = new Request(bootstrap, {
request,
response
}, request.url);
nRequest.process();
di.async(function* () {
di.setAlias('controllersPath', bootstrap.defaults.controllersPath);
di.setAlias('modulesPath', bootstrap.defaults.modulesPath);
let nRequest = new Request(bootstrap, {
request,
response
}, request.url);
yield nRequest.process();
}).catch(error => {
logger.error('Request.error', {
url: request.url,
stack: error.stack,
error
});
});
});

@@ -96,0 +106,0 @@ if (Type.isString(bootstrap.defaults.listenHost)) {

@@ -58,2 +58,34 @@ 'use strict';

* @function
* @name Controller#getComponent
* @param {String} key name of component
* @description
* Return component instance which is singleton
* @return {String}
*
* @example
* class MyAppController extends Controller {
*
* beforeIndex() {
* return [
* this.getComponent('appix/logger'),
* Promise.resolve('some async operation'),
* Promise.resolve('some other async operations')
* ];
* }
*
* actionIndex(logger, p1DataResolved, p2DataResolved) {
* logger.log('Logger works', {
* p1DataResolved: p1DataResolved,
* p2DataResolved: p2DataResolved
* })
* return 'WORKS '+ p1DataResolved + p2DataResolved; // result => WORKS some async operation some other async operations
* }
* }
*/
getComponent(key) {
return this.__request__.bootstrap.getComponent(key);
}
/**
* @since 1.0.0
* @function
* @name Controller#getMethod

@@ -64,2 +96,8 @@ *

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let method = this.getMethod();
* }
* }
*/

@@ -78,2 +116,8 @@ getMethod() {

* @return {Object}
* @example
* class Platform extends Controller {
* beforeEach() {
* let params = this.getParams();
* }
* }
*/

@@ -92,2 +136,10 @@ getParams() {

* @return {Object}
* @example
* class Platform extends Controller {
* beforeEach() {
* let url = this.getParsedUrl();
* let pathname = url.pathname;
* let protocol = url.protocol;
* }
* }
*/

@@ -105,3 +157,9 @@ getParsedUrl() {

* Get request body, return data sent to server.
* @return {Buffer}
* @return {Buffer|Object}
* @example
* class Platform extends Controller {
* beforeEach() {
* let body = this.getRequestBody();
* }
* }
*/

@@ -120,2 +178,8 @@ getRequestBody() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let pathname = this.getPathname();
* }
* }
*/

@@ -134,2 +198,8 @@ getPathname() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let domain = this.getRequestDomain();
* }
* }
*/

@@ -148,2 +218,8 @@ getRequestDomain() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let cookies = this.getRequestHeader('Cookies');
* }
* }
*/

@@ -162,2 +238,8 @@ getRequestHeader(name) {

* @return {Object}
* @example
* class Platform extends Controller {
* beforeEach() {
* let headers = this.getRequestHeaders();
* }
* }
*/

@@ -176,2 +258,8 @@ getRequestHeaders() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let local_address = this.getRequestLocalAddress();
* }
* }
*/

@@ -190,2 +278,8 @@ getRequestLocalAddress() {

* @return {Number}
* @example
* class Platform extends Controller {
* beforeEach() {
* let local_port = this.getRequestLocalPort();
* }
* }
*/

@@ -204,2 +298,8 @@ getRequestLocalPort() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let remote_port = this.getRequestRemotePort();
* }
* }
*/

@@ -218,2 +318,8 @@ getRequestRemoteAddress() {

* @return {Number}
* @example
* class Platform extends Controller {
* beforeEach() {
* let remote_port = this.getRequestRemotePort();
* }
* }
*/

@@ -229,3 +335,10 @@ getRequestRemotePort() {

* @description
* Return all cookies
* get all cookies
* @return {Object}
* @example
* class Platform extends Controller {
* beforeEach() {
* let cookies = this.getRequestCookies();
* }
* }
*/

@@ -242,3 +355,10 @@ getRequestCookies() {

* @description
* Return cookie value
* get cookie value
* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let user = this.getRequestCookie('user');
* }
* }
*/

@@ -256,2 +376,11 @@ getRequestCookie(name) {

* On end is an happening on destroy event
* @example
* class Platform extends Controller {
* beforeEach() {
* let mySharedService = this.getComponent('shared-service');
* this.onEnd(() => {
* mySharedService.delete(this.getRequestId());
* });
* }
* }
*/

@@ -265,3 +394,3 @@ onEnd(callback) {

* @function
* @name Controller#forwardUrl
* @name Controller#forwardRoute
* @param {String} route

@@ -273,4 +402,14 @@ * @param {Object} params

* @return {Promise}
* @example
* class Platform extends Controller {
* beforeEach() {
* if (/* expression *\/) {
* return this.forwardRoute('search/index', {query: 'term'});
* }
* }
* }
*/
forwardRoute(route, params) {
this.stopChain();
this.__request__.flagAsForwarder();
return this.__request__.forwardRoute(route, params);

@@ -288,4 +427,14 @@ }

* @return {Promise}
* @example
* class Platform extends Controller {
* beforeEach() {
* if (/* expression *\/) {
* return this.forwardUrl('/search?query=term');
* }
* }
* }
*/
forwardUrl(url) {
this.stopChain();
this.__request__.flagAsForwarder();
return this.__request__.forwardUrl(url);

@@ -302,2 +451,8 @@ }

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let route = this.getRequestRoute();
* }
* }
*/

@@ -316,2 +471,8 @@ getRequestRoute() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let controller = this.getRequestController();
* }
* }
*/

@@ -330,2 +491,8 @@ getRequestController() {

* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let action = this.getRequestAction();
* }
* }
*/

@@ -342,4 +509,10 @@ getRequestAction() {

* @description
* Returns request id
* Returns uuid request id
* @return {String}
* @example
* class Platform extends Controller {
* actionIndex() {
* let uuid = this.getRequestId();
* }
* }
*/

@@ -353,2 +526,34 @@ getRequestId() {

* @function
* @name Controller#getUserAgent
*
* @description
* Get user agent
* @return {String}
* @example
* class Platform extends Controller {
* beforeEach() {
* let ua = this.getUserAgent();
* if (/android/i.test(ua)) {
* return this.forwardRoute('platform/mobile', this.getParams());
* }
* return this.forwardRoute('platform/desktop', this.getParams());
* }
* }
* class Desktop extends Platform {
* actionIndex() {
*
* }
* }
* class Mobile extends Platform {
* actionIndex() {
*
* }
* }
*/
getUserAgent() {
return this.getRequestHeader('User-Agent');
}
/**
* @since 1.0.0
* @function
* @name Controller#setResponseStatusCode

@@ -358,2 +563,10 @@ * @param {Number} num status code number

* Set status code which will be sent to client
* @example
* class Error extends Controller {
* actionHandler() {
* if (/* expression *\/) {
* this.setResponseStatusCode(504)
* }
* }
* }
*/

@@ -367,11 +580,18 @@ setResponseStatusCode(num) {

* @author Igor Ivanovic
* @method Controller#setResponseCookie
* @param key {String} cookie name
* @param value {String} cookie value
* @param expires {String|Object|Number} expire date
* @param path {String} cookie path
* @param domain {String} cookie domain
* @param isHttpOnly {Boolean} is http only
* @function
* @name Controller#setResponseCookie
* @param {String} key cookie name
* @param {String} value cookie value
* @param {String|Object|Number} expires expire date
* @param {String} path cookie path
* @param {String} domain cookie domain
* @param {Boolean} isHttpOnly is http only
* @description
* Sets an cookie header
* @example
* class User extends Controller {
* actionLogin() {
* this.setResponseCookie('user', 'id-1', 30)
* }
* }
*/

@@ -389,2 +609,10 @@ setResponseCookie(key, value, expires, path, domain, isHttpOnly) {

* Sets an response header
* @example
* class JSON extends Controller {
* afterEach(html) {
* if (!this.hasResponseHeader('Content-Type')) {
* this.setResponseHeader('Content-Type', 'application/json');
* }
* }
* }
*/

@@ -402,2 +630,10 @@ setResponseHeader(key, value) {

* @return {Boolean}
* @example
* class JSON extends Controller {
* afterEach(html) {
* if (!this.hasResponseHeader('Content-Type')) {
* this.setResponseHeader('Content-Type', 'application/json');
* }
* }
* }
*/

@@ -533,4 +769,3 @@ hasResponseHeader(key) {

* @example
* // route home/index
* class MyAppController extends Controller {
* class MyAppController extends Controller {
*

@@ -551,3 +786,3 @@ * beforeEach() {

*
* }
* }
*/

@@ -565,2 +800,13 @@ stopChain() {

* Redirect to page
* @example
* class User extends Controller {
* beforeEach() {
* if (!this.isLoggedIn) {
* return this.redirect(this.createUrl('user/login'))
* }
* }
* actionIndex() {
*
* }
* }
*/

@@ -578,2 +824,10 @@ redirect(url, code) {

* before each request do some logic if needed
* @example
* class User extends Controller {
* beforeEach() {
* if (!this.isLoggedIn) {
* return this.redirect(this.createUrl('user/login'))
* }
* }
* }
*/

@@ -591,2 +845,12 @@ beforeEach() {

* after each request do some logic if needed
* @example
* class User extends Controller {
* afterEach(html) {
* if (this.getMethod() === 'GET') {
* let cache = this.getComponent('mycache');
* cache.set(this.getPathname(), html);
* }
* return html;
* }
* }
*/

@@ -593,0 +857,0 @@ afterEach(action) {

@@ -13,2 +13,11 @@ 'use strict';

* @name DI
* @example
* 'use strict';
* let Controller = di.load('@{appix}/controller');
* let Filter = di.load('@{appix}/filter');
* class Demo extends Controller {
* actionIndex() {
*
* }
* }
*/

@@ -15,0 +24,0 @@ class DI extends DiNode {

@@ -23,4 +23,7 @@ 'use strict';

* @constructor
* @protected
* @description
* This class is responsible for processing request
* This class is responsible for processing request.
* Developer don't have access to request class itself, instead of it,
* API is provided to developer in order to manipulate with request
*/

@@ -43,2 +46,3 @@ class Request extends Type {

isForwarded: Type.BOOLEAN,
isForwarder: Type.BOOLEAN,
isRedirected: Type.BOOLEAN,

@@ -57,8 +61,9 @@ statusCode: Type.NUMBER,

this.isForwarded = config.isForwarded || false;
this.isForwarder = false;
this.isRedirected = false;
this.id = config.id || di.uuid();
this.id = di.uuid();
this.url = url;
this.parsedUrl = URLParser.parse(this.url, true);
this.data = Type.isArray(config.data) ? config.data : [];
this.events = config.events || new EventEmitter();
this.events = new EventEmitter();
this.statusCode = 200;

@@ -77,8 +82,16 @@ this.responseHeaders = {};

}
}
this.response.on('destory', () => {
this.events.emit('destory');
this.events.removeAllListeners();
this.destroy();
});
/**
* @since 1.0.0
* @function
* @name Request#destroy
* @private
* @description
* Destroy all references to free memory
*/
destroy() {
this.events.emit('destroy');
this.events.removeAllListeners();
super.destroy();
}

@@ -267,3 +280,3 @@

onEnd(callback) {
this.events.once('destory', callback);
this.events.once('destroy', callback);
}

@@ -328,9 +341,10 @@

* @author Igor Ivanovic
* @method Request#setResponseCookie
* @param key {String} cookie name
* @param value {String} cookie value
* @param expires {String|Object|Number} expire date
* @param path {String} cookie path
* @param domain {String} cookie domain
* @param isHttpOnly {Boolean} is http only
* @function
* @name Request#setResponseCookie
* @param {String} key cookie name
* @param {String} value cookie value
* @param {String|Object|Number} expires expire date
* @param {String} path cookie path
* @param {String} domain cookie domain
* @param {Boolean} isHttpOnly is http only
* @description

@@ -352,3 +366,3 @@ * Sets an cookie header

}
cookie = key + "=" + value;
cookie = key + '=' + value;
if (!!expires) {

@@ -358,17 +372,17 @@ if (Type.isNumber(expires)) {

date.setTime(date.getTime() + expires);
cookie += "; Expires=" + date.toGMTString();
cookie += '; Expires=' + date.toGMTString();
} else if (Type.isString(expires)) {
cookie += "; Expires=" + expires;
cookie += '; Expires=' + expires;
} else if (Type.isDate(expires)) {
cookie += "; Expires=" + expires.toGMTString();
cookie += '; Expires=' + expires.toGMTString();
}
}
if (!!path) {
cookie += "; Path=" + path;
cookie += '; Path=' + path;
}
if (!!domain) {
cookie += "; Domain=" + domain;
cookie += '; Domain=' + domain;
}
if (!!isHttpOnly) {
cookie += "; HttpOnly";
cookie += '; HttpOnly';
}

@@ -478,2 +492,3 @@ this.setResponseHeader('Set-cookie', cookie);

forward(url, config) {
if (url === this.url) {

@@ -487,12 +502,9 @@ throw new error.HttpException(500, 'Cannot be forwarded to same url', {

request: this.request,
id: this.id,
response: this.response,
requestCookies: this.requestCookies,
isForwarded: true,
events: this.events,
data: this.data
}, config), url);
let process = nRequest.process();
nRequest.request.emit('end');
return process;
return nRequest.process();
}

@@ -603,2 +615,3 @@

forwardUrl: this.forwardUrl.bind(this),
flagAsForwarder: () => this.isForwarder = true,
id: this.id,

@@ -611,2 +624,3 @@ bootstrap: this.bootstrap,

if (!(controller instanceof Controller)) {

@@ -625,13 +639,30 @@ throw new error.HttpException(500, `${controllerName} must be inherited from @{appix}/controller`, {

action = yield controller.applyBeforeEachFilters();
if (!request.isForwarded) {
action = yield controller.applyBeforeEachFilters();
}
if (controller.isChaining()) {
action = yield controller.beforeEach(action);
if (Type.isArray(action)) {
action = yield Promise.all(action);
action = yield controller.beforeEach.apply(controller, action);
} else {
action = yield controller.beforeEach(action);
}
}
if (Type.isFunction(controller[beforeKey]) && controller.isChaining()) {
action = yield controller[beforeKey](action);
if (Type.isArray(action)) {
action = yield Promise.all(action);
action = yield controller[beforeKey].apply(controller, action);
} else {
action = yield controller[beforeKey](action);
}
}
if (controller.isChaining()) {
if (Type.isFunction(controller[actionKey])) {
action = yield controller[actionKey](action);
if (Type.isArray(action)) {
action = yield Promise.all(action);
action = yield controller[actionKey].apply(controller, action);
} else {
action = yield controller[actionKey](action);
}
} else {

@@ -648,14 +679,34 @@ throw new error.HttpException(500,

if (Type.isFunction(controller[afterKey]) && controller.isChaining()) {
action = yield controller[afterKey](action);
if (Type.isArray(action)) {
action = yield Promise.all(action);
action = yield controller[afterKey].apply(controller, action);
} else {
action = yield controller[afterKey](action);
}
}
if (controller.isChaining()) {
action = yield controller.afterEach(action);
if (Type.isArray(action)) {
action = yield Promise.all(action);
action = yield controller.afterEach.apply(controller, action);
} else {
action = yield controller.afterEach(action);
}
}
// on redirection don't apply filters
if (!request.isRedirected) {
return yield controller.applyAfterEachFilters(action);
if (!request.isRedirected && !request.isForwarder) {
if (Type.isArray(action)) {
action = yield Promise.all(action);
return yield controller.applyAfterEachFilters.apply(controller, action);
} else {
return yield controller.applyAfterEachFilters(action);
}
}
return action;
}).then(item => this.render(item));
}).then(data => {
if (this.isForwarded) {
return data;
}
return this.render(data);
});
}

@@ -676,5 +727,5 @@

if (!this.isForwarded) {
this.response.once('finish', () => this.response.emit('destory'));
this.response.once('finish', () => this.destroy());
// destroy if connection was terminated before end
this.response.once('close', () => this.response.emit('destory'));
this.response.once('close', () => this.destroy());
// push data

@@ -684,3 +735,5 @@ this.request.on('data', item => this.data.push(item));

// on data end process request
return new Promise(resolve => this.request.on('end', resolve))
let request = this.isForwarded ? Promise.resolve(true) : new Promise(resolve => this.request.on('end', resolve));
return request
.then(() => {

@@ -733,3 +786,10 @@ logger.info('Route.parseRequest', {

})
.catch(error => this.render(error.stack));
.catch(error => this.render(error.stack))
.catch(error => logger.error('Error in parsing error response', {
id: this.id,
url: this.url,
request: this.getParsedUrl(),
method: this.getMethod(),
error
}))
}

@@ -736,0 +796,0 @@ }

@@ -21,2 +21,26 @@ 'use strict';

* Route rule is used to add route definitions to router
* @example
* class DynamicRule extends RouteRule {
* parseRequest() {
*
* }
* createUrl() {
*
* }
* }
*
* // during bootstrap process add dynamic route rule
* let router = bootstrap.getComponent('appix/router');
* router.add(DynamicRule);
* // add static routes
* router.add([
* {
* url: '/',
* route: 'app/Index'
* },
* {
* url: '/favicon.ico',
* route: 'app/Favicon'
* }
* ]);
*/

@@ -23,0 +47,0 @@ class RouteRule extends Type {

@@ -5,3 +5,3 @@ {

"description": "Lightweight application framework with dyependency injection and dynamic type checking for node js",
"version": "1.0.0-alpha-02",
"version": "1.0.0-alpha-03",
"dependencies": {

@@ -8,0 +8,0 @@ "di-node": "0.2.x",

@@ -12,2 +12,4 @@ # Appix 1.0.0-alpha-02 [![Build Status](https://travis-ci.org/igorzg/appix.svg?branch=master)](https://travis-ci.org/igorzg/appix)

[Documentation wiki](https://github.com/igorzg/appix/wiki)

@@ -52,11 +54,11 @@ **Hello world example in appix**

url: '/',
route: 'app/Index'
route: 'home/Index'
},
{
url: '/goto301',
route: 'app/Redirect301'
route: 'home/Redirect301'
},
{
url: '/goto',
route: 'app/Redirect'
route: 'home/Redirect'
},

@@ -77,2 +79,3 @@ {

let Controller = di.load('@{appix}/controller');
// Controllers can be inherited as many levels as you need
class Home extends Controller {

@@ -79,0 +82,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc