成功在BAE上部署ghost 5.0
这周摸索着网站的建设,终于在今天成功上线!这里要谢谢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和评论区,接下来就是搞定他们了。
!参考学习
成功在BAE上部署ghost 5.0的更多相关文章
- BAE上部署Ghost 0.5.1注意事项
BAE上部署Ghost可参考基本安装上述安装使用的是ghost0.4.7版本 在ghost 0.5 中为了解决测试时事件侦听器过多引发的警告,在注册single事件时,将代码由原先的 process. ...
- 在CentOS 7上部署Ghost博客
作者:waringid 一.简介 跟静态博客不同的是,Ghost 这种轻量级的动态博客,有一个管理后台,可以直接写作和管理博客.本质上,跟 WordPress 是相通的,只是 Ghost 搭建在 No ...
- 在BAE上部署Pomelo
BAE升级到3.0后顿时感觉好用了很多,俨然云主机的感觉. 底下我将分享我在BAE上部署Pomelo的过程. 首先需要拥有一个BAE的执行单元.没有的可以自行百度并部署. 接着svn得出代码到本地.此 ...
- 关于在BAE上部署ThinkPHP框架的问题
现在有点小兴奋,因为在在BAE上部署ThinkPHP框架的问题快折腾一天了,午觉都没睡,不过没白整总算有点结果.不扯淡了,直入正题吧. 之前熟悉ThinkPHP框架,想在BAE上用ThinkPHP做点 ...
- Coding上部署Ghost博客
Ghost构建于Node.js平台之上.支持0.10.*版本号的Node.js. 在你的本地计算机上执行Ghost事实上非常easy,前提是你已经安装了Node.js. 什么是Node.js? 略过 ...
- 那些在BAE上部署node.js碰到的坑
在BAE上使用node.js半年多了,其中碰到了不少因为BAE云环境限制碰到的坑 写下来大家碰到了,也不用那么麻烦的去看好几天代码了,直接对症下药 官方公布的坑有: BAE是使用package.jso ...
- IIS 6.0上部署.NET 4.0网站
最近需要把VS2010开发的网站部署到Windows Server 2003的服务器上去, Windows Server 2003操作系统自带的为IIS 6.0,IIS 6.0一般只支持.NET 2. ...
- 在CentOS上部署kubernetes1.9.0集群
原文链接: https://jimmysong.io/kubernetes-handbook/cloud-native/play-with-kubernetes.html (在CentOS上部署kub ...
- Ubuntu上部署Ghost博客
所有文章搬运自我的个人主页:sheilasun.me 刚刚成功把自己的ghost博客部署到Linode VPS上了,在这里回顾并顺便整理一下从购买域名到部署代码到服务器的整个过程. 购买域名 万网或者 ...
随机推荐
- KafkaSpout分析:配置
public KafkaSpout(SpoutConfig spoutConf) { _spoutConfig = spoutConf;} 基于0.93版本的Storm SpoutConfig继承自K ...
- Linq基本用法
- VO,DTO,DO,PO的划分
实体类(VO,DTO,DO)的划分 经常会接触到VO,DO,DTO的概念,本文从领域建模中的实体划分和项目中的实际应用情况两个角度,对这几个概念进行简析. 得出的主要结论是:在项目应用中,VO对应 ...
- SQLite入门与分析(一)---简介
写在前面:出于项目的需要,最近打算对SQLite的内核进行一个完整的剖析,在此希望和对SQLite有兴趣的一起交流.我知道,这是一个漫长的过程,就像曾经去读Linux内核一样,这个过程也将是辛苦的,但 ...
- CSS+DIV 布局三种定位方式
一.普通流 普通流中元素框的位置由元素在HTML中的位置决定.块级元素从上到下依次排列,框之间的垂直距离由框的垂直margin计算得到.行内元素在一行中水平布置. 二.定位 1.相对定位 被看作普通流 ...
- Rails中的MIME类型
layout title date comments categories post rails的中的MIME类型 2014-09-08 21:40 true ruby Rails开发中经常使用不同的 ...
- Android开发之ListView-ArrayAdapter的使用
ArrayAdapter: ArrayAdapter<String>(Context context, int resource, int textViewResourceId, Stri ...
- createSQLQuery与createQuery的区别
本文原址 : http://stta04.javaeye.com/blog/377633hibernate 中createQuery与createSQLQuery 昨晚帮同事看代码到凌晨2点多,今早6 ...
- 函数buf_ptr_get_fsp_addr
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID 34 /****************************************************** ...
- 通用权限管理系统Ver2.0
通用权限管理系统Ver2.0平台采用kendo+mvc4+Nhibernate技术实现,底层采用自定义ORM实现数据库底层代码,支持Oracle.SqlServer.mysql等常用数据库,界面采用k ...