kk-koa-framework
Advanced tools
Comparing version 1.0.5 to 1.0.6
73
index.js
const Koa = require('koa') | ||
const app = new Koa() | ||
const path = require('path') | ||
const serve = require('koa-static') | ||
global.kk = app | ||
class Framework{ | ||
constructor(){ | ||
let app = new Koa() | ||
app.$$ = {} | ||
app.LIFT_TIME = Date.now() | ||
this.ROOT_DIR = process.cwd() | ||
app.LIFT_TIME = Date.now() | ||
this.staticPath = [] | ||
let ROOT_DIR = process.cwd() | ||
global.kk = app | ||
this.app = app | ||
} | ||
app.$$ = {} | ||
addStatic(p){ | ||
this.staticPath.push(p) | ||
} | ||
let staticPath = [] | ||
setViewPath(p){ | ||
this.app.$$.VIEW_DIR = p | ||
} | ||
app.setViewPath = p => app.$$.VIEW_DIR = p | ||
setSourcePath(p){ | ||
this.app.$$.SOURCE_DIR = p | ||
} | ||
app.addStatic = p => { | ||
staticPath.push(p) | ||
} | ||
startup(){ | ||
let app = this.app | ||
app.$$.ROOT_DIR = this.ROOT_DIR | ||
app.setSourcePath = p => app.$$.SOURCE_DIR = p | ||
app.startup = () => { | ||
app.$$.ROOT_DIR = ROOT_DIR | ||
app.$$.CONFIG_DIR = path.join(ROOT_DIR, 'config') | ||
app.$$.SOURCE_DIR = app.$$.SOURCE_DIR || path.join(ROOT_DIR, 'src') | ||
app.$$.VIEW_DIR = app.$$.VIEW_DIR || path.join(ROOT_DIR, 'views') | ||
if(staticPath.length == 0){ | ||
app.$$.STATIC_PATH = path.join(ROOT_DIR,'.tmp/public') | ||
}else{ | ||
for(let p of staticPath){ | ||
app.use(serve(p)) | ||
app.$$.CONFIG_DIR = path.join(this.ROOT_DIR, 'config') | ||
app.$$.SOURCE_DIR = app.$$.SOURCE_DIR || path.join(this.ROOT_DIR, 'src') | ||
app.$$.VIEW_DIR = app.$$.VIEW_DIR || path.join(this.ROOT_DIR, 'views') | ||
if(this.staticPath.length == 0){ | ||
app.$$.STATIC_PATH = path.join(this.ROOT_DIR,'.tmp/public') | ||
}else{ | ||
for(let p of this.staticPath){ | ||
app.use(serve(p)) | ||
} | ||
} | ||
require('./src/setup')(app) | ||
var listener = app.listen(app.$$.config.port || 6880, () => { | ||
console.log('Listening on port ' + listener.address().port) | ||
}) | ||
} | ||
require('./src/setup')(app) | ||
var listener = app.listen(app.$$.config.port || 6880, () => { | ||
console.log('Listening on port ' + listener.address().port) | ||
}) | ||
} | ||
module.exports = app | ||
module.exports = Framework |
{ | ||
"name": "kk-koa-framework", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "kk koa mvc webframework", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,5 +0,7 @@ | ||
const app = require('../index') | ||
const Koa = require('../index') | ||
const app = new Koa() | ||
console.log(process.cwd()) | ||
app.startup() |
12556
21
380