我能说很后悔四点钟爬起来写了个(一)config么。。。
在Ghost blog的Node server启动后,首先做好config工作,接下来就是blog系统本身的初始化,在很多初始化步骤中,以笔者现在龟爬的阅读进度来看,还不能理解为什么,只能写是什么。
在入口server.js中,首先调用了ghost.init()方法,调用代码只有一行就省略不贴了。而这个ghost对象,就是整个系统的核心对象,从名字上就能看出来。他是从一个Ghost类上new出来的。而我们今天要讲的init就是Ghost类中的初始化方法。
ghost在./core目录下,init函数如下:
// Initialise the application
Ghost.prototype.init = function () {
var self = this;
function doFirstRun() {
//...... 省略
}
function initDbHashAndFirstRun() {
//.......省略
}
// ### Initialisation
return when.join(
// Initialise the models
self.dataProvider.init(),
// Calculate paths
self.getPaths(),
// Initialise mail after first run
self.mail.init(self)
).then(function () {
// Populate any missing default settings
return models.Settings.populateDefaults();
}).then(function () {
// Initialize the settings cache
return self.updateSettingsCache();
}).then(function () {
return when.join(
// Check for or initialise a dbHash.
initDbHashAndFirstRun(),
// Initialize plugins
self.initPlugins(),
// Initialize the permissions actions and objects
permissions.init()
);
}).otherwise(errors.logAndThrowError);
};
那么按着顺序一个一个步骤简单介绍一下吧。
1. self.dataProvider.init() : 调用了一个类自身属性dataProvider的init方法,这个dataProvider在上文有定义
models = require('./server/models'),
dataProvider: models,
但其实models是个目录,下面是诸如user,post,tag,setting等模块。那么话说回来,models.init()到底做了什么,它就做了一件事:比较当前的blog数据版本和默认的数据版本是否一致,如果不一致会做更新,甚至是直接抛错。
2. self.getPaths() :调用类自身的方法getPaths(),所做的工作就是生成主题(themes)和插件(plugins)所在的路径,以供之后其他方法调用。
3. self.mail.init(self) : 很明显,这是在初始化邮件模块
4. models.Settings.populateDefaults() : setting里面其实存有blog的很多基本信息,诸如:
databaseVersion
title
description
email
logo
cover
defaultLang
postsPerPage
forceI18n
activeTheme
activePlugins
installedPlugins
而,这一步代码,所做的工作就是去看看当前blog中的这些key有没有缺少的,如果少了,就用defaults的value给补上
5. self.updateSettingsCache() : 将当前的基本信息给更新到cache里,就是第4步里那些信息,这个方法其实还有一个参数settings,如果传了就用所传的,不传的话就从db里去找数据。
6. initDbHashAndFirstRun() :初始化dbHash哈希值,dbHash也是在settings里的一项数据,这里做个判断,如果已存在就用现成的,不存在就用uuid.v4()重新生成,dbhash的作用从注释上看是用于cookie相关的操作,实际用处暂时不知道。
// Holds the dbhash (mainly used for cookie secret)
instance.dbHash = undefined;
同时,生成好dbHash后,就进行First run,在console上输出一些信息,上面代码里就省略了。
7. self.initPlugins() : 对插件进行加载,不过一开始当然是没有插件的
8. permissions.init() : 允许动作的初始化,笔者返回了{ edit: [ 'post' ], remove: [ 'post' ], create: [ 'post' ] }这样的信息,但是用处不明。
先写这么多,每个步骤其实都可以深入下去,下次写啥呢……
分享到:
相关推荐
ghost远控,是一款经典的远控.对于想写远控的朋友,深入研究ghost源码无疑是最有效的方法.但是对于初学者来说,独自研究无疑是有难度的.所以有老师讲解,一定会事半功倍!
ghost 3.6 源码 VC6.0+SDK ghost 3.6 源码 VC6.0+SDK
ghost3.75源码
ghOst3.6源码修改后过大多数杀软ghOst3.6源码修改后过大多数杀软ghOst3.6源码修改后过大多数杀软ghOst3.6源码修改后过大多数杀软ghOst3.6源码修改后过大多数杀软
Ghost远控源码免杀详讲Ghost远控源码Ghost远控源码免杀详讲-2.rar免杀详讲-2.rar
Ball版G Ball版GHOST3.6源码HOST3.6源码
GHOST3.75源码
完整版ghost3.6源码
ghost 2012 VC++远控源码,要的赶紧!
ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控ghost远控...
功能强大的 功能强大的 ghost 3.6
最新源码支持WI7 2008 XP 2003 等 大部系统
Ghost全免杀源码Ghost全免杀源码
GHOST 3.6 源码教程 我觉得挺好的 啊 GHOST 3.6 源码教程
ghost 3.6 原版源码,无硬盘锁,安全漏洞学习分析必备
ghost源码免杀全套教程+源码很难得的全套教程和源码
易语言源码易语言一键Ghost源码.rar
1.正确编译Ghost远控 安装VC6.0和更新SDK vc 6.0龙卷风企业版 SDK下载地址: http://www.namipan.com/d/VC98.rar/184e40de31642ee25251a35e1efcefbdc011226249be0e04 然后解压到vc++安装目录的VC98目录里,覆盖掉...
饭客VIP远控GHOST编译源码带金牌验证