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

thinkjs

Package Overview
Dependencies
Maintainers
1
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thinkjs - npm Package Compare versions

Comparing version 3.0.0-alpha2 to 3.0.0-beta1

28

lib/application.js

@@ -162,2 +162,3 @@ const path = require('path');

runInCli(cliPath){
think.app.emit('appReady');
mockHttp({

@@ -189,16 +190,21 @@ url: cliPath,

try{
instance.loadAll(!!argv.path);
if(argv.path){
think.isCli = true;
instance.loadAll('worker');
return this.runInCli(argv.path);
}else if(cluster.isMaster){
instance.loadAll('master');
this.runInMaster();
}else if(thinkCluster.isAgent()){
instance.loadAll('agent');
this.runInAgent();
}else{
instance.loadAll('worker');
this.runInWorker(argv);
}
}catch(e){
think.logger.error(e);
console.error(e);
}
if(argv.path){
return this.runInCli(argv.path);
}else if(cluster.isMaster){
this.runInMaster();
}else if(thinkCluster.isAgent()){
this.runInAgent();
}else{
this.runInWorker(argv);
}
}
}

@@ -169,5 +169,3 @@ const helper = require('think-helper');

}
if(name === undefined && value === undefined) {
return this[PARAM];
}
if(!name) return this[PARAM];
if(helper.isObject(name)){

@@ -179,2 +177,10 @@ this[PARAM] = Object.assign(this[PARAM], name);

if(value === undefined){
// this.param('a,b')
if(name.indexOf(',') > -1){
let value = {};
name.split(',').forEach(item => {
value[item] = this[PARAM][item];
});
return value;
}
return this[PARAM][name];

@@ -194,5 +200,2 @@ }

}
if(name === undefined && value === undefined) {
return this[POST];
}
if(!name) return this[POST];

@@ -204,2 +207,10 @@ if(helper.isObject(name)){

if(value === undefined){
// this.param('a,b')
if(name.indexOf(',') > -1){
let value = {};
name.split(',').forEach(item => {
value[item] = this[POST][item];
});
return value;
}
return this[POST][name];

@@ -206,0 +217,0 @@ }

@@ -7,7 +7,3 @@ const getConfigFn = require('think-config').getConfigFn;

const Crontab = require('think-crontab');
const cluster = require('cluster');
const thinkCluster = require('think-cluster');
const debug = require('debug')('think');
require('./think.js');

@@ -58,5 +54,2 @@ // ThinkJS root path

const middlewares = think.loader.loadMiddleware(think.app);
if(debug.enabled){
think.logger.info('middleware length', middlewares.length);
}
middlewares.forEach(middleware => {

@@ -96,4 +89,3 @@ think.app.use(middleware);

*/
loadAll(cli){
let type = 'master';
loadAll(type){
this.initPath();

@@ -104,11 +96,8 @@ think.loader = new Loader(think.APP_PATH, thinkPath, think.app);

if(!cluster.isMaster || cli){
if(type !== 'master'){
this.loadExtend();
this.loadData();
this.loadMiddleware();
this.loadCrontab();
if(cli){
type = 'cli';
}else{
type = thinkCluster.isAgent() ? 'agent' : 'worker';
if(!think.isCli){
this.loadCrontab();
}

@@ -115,0 +104,0 @@ }

@@ -5,2 +5,3 @@ const Koa = require('koa');

const bluebird = require('bluebird');
const assert = require('assert');
const messenger = require('think-cluster').messenger;

@@ -26,2 +27,11 @@

/**
* think env
*/
think.__defineGetter__('env', () => think.app.env);
/**
* is cli mode
*/
think.isCli = false;
/**
* add think to think.app

@@ -54,2 +64,52 @@ */

*/
think.Logic = class Logic extends think.Controller {};
think.Logic = class Logic extends think.Controller {};
const getClass = function(type, name, m){
let mcls = think.app[type];
let cls = null;
if(think.app.modules.length){
if(mcls[m]){
cls = mcls[m][name];
}
if(!cls && m !== 'common' && mcls.common){
cls = mcls.common[name];
}
}else{
cls = mcls[name];
}
return cls;
}
/**
* get controller instance
* @param {String} name
* @param {Object} ctx
* @param {String} m
*/
think.controller = (name, ctx, m = 'common') => {
const cls = getClass('controllers', name, m);
assert(cls, `can not find controller:${name}`);
return new cls(ctx);
}
/**
* get service
*/
think.service = (name, m) => {
return getClass('services', name, m);
}
// before start server
let promises = [];
think.beforeStartServer = fn => {
if(fn) {
assert(helper.isFunction(fn), 'fn in think.beforeStartServer must be a function');
return promises.push(fn());
}
const promise = Promise.all(promises);
const timeout = helper.ms(think.config('startServerTimeout'));
const timeoutPromise = helper.timeout(timeout).then(() => {
const err = new Error(`waiting for start server timeout, time: ${timeout}ms`);
return Promise.reject(err);
});
return Promise.race([promise, timeoutPromise]);
}
{
"name": "thinkjs",
"description": "ThinkJS - Use full ES6/7 features to develop web applications, Support TypeScript",
"version": "3.0.0-alpha2",
"version": "3.0.0-beta1",
"author": {

@@ -6,0 +6,0 @@ "name": "welefen",

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