這周摸索着網站的建設,終於在今天成功上線!這里要謝謝ghost中文網和群里的網友,他的博客在這opengiser。他們的幫助太重要了。現在把過程記錄下來,共同學習。試運營地址在edwardesire。 現在放ACE上了
- 下載安裝包
總共需要下載2個東西。
-
新建BAE工程
在百度開發雲平台的管理控制台下一次點擊:開發者服務管理->創建工程->創建->應用引擎-添加部署-創建。這樣nodejs的環境就建好了。這里一起把數據庫也建立起來。這里我使用的是mysql,點擊應用引擎中的擴展服務即可,添加新服務當然使用免費版的咯。 -
配置
接下來就是在本地把源碼配置好咯。將工程clone下來后,用ghost源碼覆蓋掉。在本地運行命令npm install,后將下載好的mysql覆蓋掉node_modules下原有的。然后打開根目錄的config.example.js將database段修改為如下:production: { database: { client: 'mysql', connection: { host: 'sqld.duapp.com', port: 4050, user: '#####', //你的ak password: '#####', //你的sk database: '#####',//數據庫名 charset: 'utf8' }, debug: false }, server: { host: '127.0.0.1', port: '18080' } }
最后再修改根目錄的config.example.js。修改啟動命令,將"start": "node index"改為"start": "node index.js"。並去掉依賴dependencies、optionalDependencies、devDependencies這三項。
-
修改5.0中與BAE不兼容的部分
按照q友悟道所說需要注釋掉core/server/index.js中305行的ghostStartMessages()。原因是這個方法的內部與BAE不兼容。 -
圖像存儲問題
在package.json中的dependencies添加七牛的依賴包,在config.example.js中production和添加:qiniu: { bucketname: '#####', //七牛雲的目錄名 ACCESS_KEY: '#####', //七牛雲的ak SECRET_KEY: '#####', //七牛雲的sk root: '/image/', prefix: 'http://' //七牛的空間域名 }
最后在core/server/storage做兩個操作
+ 覆蓋index.js文件
var errors = require('../errors'),
storage;
var qiniuConfig = require('../config/').qiniu;
function get_storage() {
// TODO: this is where the check for storage apps should go
// Local file system is the default
var storageChoice = qiniuConfig? 'qiniu':'localfilesystem';
if (storage) {
return storage;
}
try {
// TODO: determine if storage has all the necessary methods
storage = require('./' + storageChoice);
} catch (e) {
errors.logError(e);
}
return storage;
}
module.exports.get_storage = get_storage;
+ 並添加一個qiniu.js文件
// # Local File System Image Storage module
// The (default) module for storing images, using the local file system
var _ = require('lodash'),
express = require('express'),
fs = require('fs-extra'),
nodefn = require('when/node/function'),
path = require('path'),
when = require('when'),
config = require('../config'),
errors = require('../errors'),
baseStore = require('./base'),
crypto = require('crypto'),
qiniu = require('qiniu'),
qiniuConfig = config.qiniu,
qiniuStore;
qiniu.conf.ACCESS_KEY = qiniuConfig.ACCESS_KEY;
qiniu.conf.SECRET_KEY = qiniuConfig.SECRET_KEY;
qiniu.conf.USER_AGENT = 'Ghost 0.4.2';
var putPolicy = new qiniu.rs.PutPolicy(qiniuConfig.bucketname),
uptoken = putPolicy.token();
qiniuStore = _.extend(baseStore, {
// ### Save
// Saves the image to storage (the file system)
// - image is the express image object
// - returns a promise which ultimately returns the full url to the uploaded image
'save': function (image) {
var saved = when.defer(),
md5sum = crypto.createHash('md5'),
ext = path.extname(image.name),
targetDirRoot = qiniuConfig.root,
targetFilename,
key,
extra = new qiniu.io.PutExtra();
var savedpath = path.join(config.paths.imagesPath, image.name);
nodefn.call(fs.copy, image.path, savedpath).then(function(){
return nodefn.call(fs.readFile, savedpath);
}).then(function(data) {
md5 = md5sum.update(data).digest('hex');
targetFilename = path.join(targetDirRoot, md5.replace(/^(\w{1})(\w{2})(\w+)$/, '$1/$2/$3')) + ext;
targetFilename = targetFilename.replace(/\\/g, '/');
key = targetFilename.replace(/^\//, '');
return nodefn.call(qiniu.io.put, uptoken, key, data, extra);
}).then(function () {
return nodefn.call(fs.unlink, savedpath).then(function(){
return nodefn.call(fs.unlink, image.path);
}).otherwise(errors.logError);
}).then(function () {
// prefix + targetFilename
var fullUrl = qiniuConfig.prefix + targetFilename;
return saved.resolve(fullUrl);
}).otherwise(function (e) {
errors.logError(e);
return saved.reject(e);
});
return saved.promise;
},
'exists': function (filename) {
// fs.exists does not play nicely with nodefn because the callback doesn't have an error argument
var done = when.defer();
fs.exists(filename, function (exists) {
done.resolve(exists);
});
return done.promise;
},
// middleware for serving the files
'serve': function () {
var ONE_HOUR_MS = 60 * 60 * 1000,
ONE_YEAR_MS = 365 * 24 * ONE_HOUR_MS;
// For some reason send divides the max age number by 1000
return express['static'](config.paths.imagesPath, {maxAge: ONE_YEAR_MS});
}
});
module.exports = qiniuStore;
最后注釋掉fonts.googleapis相關的字體加載,就可以上傳代碼、發布咯。
- Next
個人覺得需要文章分類、歸檔archive和評論區,接下來就是搞定他們了。
!參考學習