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

okgo

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

okgo - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

lib/core/error.js

3

lib/core/cache.js

@@ -132,2 +132,3 @@ /**

get(key){
let self = this
return new Promise( async function(resolve, reject){

@@ -138,3 +139,3 @@

this.__message('get',{
self.__message('get',{
'key': key

@@ -141,0 +142,0 @@ })

@@ -11,5 +11,8 @@ /**

constructor(){
constructor(req, res){
let that = this;
this.ctx = {
req: req,
res: res,
url: req ? req.url : {},

@@ -24,9 +27,2 @@ // 结束请求,返回内容

// 设置请求环境
async __setReqRes(req, res, urlobj)
{
this.ctx.req = req;
this.ctx.res = res;
this.ctx.url = urlobj;
}

@@ -45,3 +41,4 @@ // 输出

}
res.writeHead(200, {'Content-Type': contype+'; charset=utf-8'})
res.setHeader('Content-Type', contype+'; charset=utf-8')
res.writeHead(200)
res.end( stuff );

@@ -48,0 +45,0 @@

@@ -12,57 +12,73 @@ /**

constructor(){
this.middlewares = []; // 中间件列表
this.pathary = {GET:[],POST:[]};
this.pathmap = {GET:{},POST:{}};
this.middlewares = [] // 中间件列表
this._route_static = {} // 静态路由
this._route_regexp = [] // 动态匹配查找
return this
}
// 添加中间件
async addMiddleware(middleware){
this.middlewares.push(middleware);
// GET 请求
get(...arg) {
this.request( 'GET', ...arg )
return this
}
// GET 请求
async get(...arg) { this.__addPath( 'GET', ...arg ); }
// POST 请求
async post(...arg) { this.__addPath( 'POST', ...arg ); }
post(...arg) {
this.request( 'POST', ...arg )
return this
}
// 添加
async __addPath(method, urlpath, ...middleware_and_control)
{
this.pathmap[method] = this.pathmap[method] || {};
this.pathary[method] = this.pathary[method] || [];
let routedata = [method, urlpath, ...middleware_and_control];
if( typeof urlpath == 'string' && urlpath.indexOf('/:') == -1 ){
this.pathmap[method][urlpath] = routedata;
// 请求
request (method, pathstr, ...middleware_and_control) {
method = method.toUpperCase()
let ctrlfunc = middleware_and_control.pop()
, append_middlewares = middleware_and_control
, is_static_url = ( typeof pathstr == 'string' && pathstr.indexOf('/:') == -1 )
, route_item = {
method,
method,
pathstr,
control_func: ctrlfunc,
control_class: ctrlfunc._class,
middlewares: [...this.middlewares, ...append_middlewares],
regexp: null,
regkeys: [],
}// [method, pathstr, null, null, control, [this.middlewares, ...append_middlewares]]
if( is_static_url ){
this._route_static[ pathstr ] = route_item
}else{
let keys = [];
let rex = pathRegexp(urlpath, keys);
this.pathary[method].push([rex, keys, ...routedata] );
route_item.regexp = pathRegexp(pathstr, route_item.regkeys);
this._route_regexp.push( route_item )
}
return this
}
// 添加中间件
middleware(middleware){
this.middlewares.push(middleware)
return this
}
////////////
// 输出至上下文
async __renderForContext( app_context )
__renderForContext( app_context )
{
// 结构
app_context.__router = app_context.__router || {
GET: {
ary: [],
map: {},
},
POST: {
ary: [],
map: {},
}
};
// 内容
app_context.__router.GET.ary.push( ...this.pathary.GET );
app_context.__router.POST.ary.push( ...this.pathary.POST );
Object.assign(
app_context.__router.GET.map,
this.pathmap.GET
);
Object.assign(
app_context.__router.POST.map,
this.pathmap.POST
);
// 静态
app_context._route_static = Object.assign(
app_context._route_static || {},
this._route_static
)
// 动态匹配
app_context._route_regexp = [ ...(app_context._route_regexp||[]), ...this._route_regexp ]
}

@@ -69,0 +85,0 @@

@@ -9,5 +9,5 @@ /**

const lib_loader = require('./lib/loader.js')
, lib_http = require('./lib/http.js')
, lib_cluster = require('./lib/cluster.js')
const lib_loader = require('./init/loader.js')
, lib_http = require('./init/http.js')
, lib_cluster = require('./init/cluster.js')
;

@@ -14,0 +14,0 @@

{
"name": "okgo",
"version": "0.0.2",
"version": "0.0.3",
"description": "enterprise-level high-performance web app framework",
"main": "lib/index.js",
"scripts": {},
"scripts": {
"okgo": "npm i okgo-init | mkdir app | cp -r node_modules/okgo-init/app/* ./app | cp node_modules/okgo-init/index.js ./ "
},
"repository": {

@@ -8,0 +10,0 @@ "type": "git",

okgo
===
enterprise-level high-performance web app framework
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