代码拉取完成,页面将自动刷新
同步操作将从 this_lucky/ynode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
'use strict';
var http = require('http');
var Y = require('./Y');
var WebApp = require('./web/Application');
var InvalidConfigException = require('./core/InvalidConfigException');
var Hook = require('./core/Hook');
var Logger = require('./log/Logger');
var Cookie = require('./web/Cookie');
var WebRestful = require('./web/Restful');
var WebRequest = require('./web/Request');
var WebResponse = require('./web/Response');
var Session = require('./session/Session');
var WebController = require('./web/Controller');
/**
* 入口
*/
class YNode {
/**
* constructor
*
* @param JSON config 配置信息
*/
constructor(config) {
if(undefined === config) {
throw new InvalidConfigException('The app config is required');
}
this.config = config;
this.server = null;
this.app = new WebApp(config);
}
// debug
debug(res, error) {
res.setHeader('Content-Type', 'text/plain');
res.writeHead(500);
res.end(true === this.config.debug ? error.message + '\n' + error.stack :
'The server encountered an internal error');
}
// web
requestListenerWeb(req, res) {
try {
this.app.requestListener(req, res);
} catch(e) {
this.debug(res, e);
}
}
// restful
requestListenerRestful(req, res) {
try {
WebRestful.requestListener(req, res);
} catch(e) {
this.debug(res, e);
}
}
// handler
handler(req, res) {
Hook.getInstance().trigger(req, res, () => {
if(true === this.config.useRestful) {
this.requestListenerRestful(req, res);
return;
}
this.requestListenerWeb(req, res);
});
}
/**
* 获取 http server
*
* @return http server
*/
getServer() {
return http.createServer(this.handler.bind(this));
}
/**
* listen
*
* @param int port
* @param Function callback
*
* If you want to create HTTPS server you can do so as shown here
*
* var https = require('https');
* var YNode = require('ynode');
* var app = new YNode({ ... });
* https.createServer({ ... }, app.handler.bind(app)).listen(443);
*
*/
listen(port, callback) {
this.server = this.getServer();
this.server.listen(port, callback);
}
}
/**
* handler
*/
YNode.Y = Y;
/**
* Hook
*/
YNode.Hook = Hook;
/**
* Logger
*/
YNode.Logger = Logger;
/**
* Cookie
*/
YNode.Cookie = Cookie;
/**
* Web restful
*/
YNode.WebRestful = WebRestful;
/**
* Web request
*/
YNode.WebRequest = WebRequest;
/**
* Web response
*/
YNode.WebResponse = WebResponse;
/**
* Session
*/
YNode.Session = Session;
/**
* WebController handler
*/
YNode.WebController = WebController;
module.exports = YNode;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。