成功在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上了,在这里回顾并顺便整理一下从购买域名到部署代码到服务器的整个过程. 购买域名 万网或者 ...
随机推荐
- python datetime笔记
python datetime笔记 http://mint-green.diandian.com/post/2011-09-09/4892024 获取当前时间,并通过字符串输出. 格式为:%Y-%m- ...
- HDU1411+四面体的体积
用cos sin各种乱搞之后 求出一个公式.. 但是怕精度损失厉害,还是暂且贴个公式的,copy别人的.. #include<stdio.h> #include<math.h> ...
- redis 性能监控和排查
最近项目中接连遇到redis出现瓶颈的问题,现在把排查的一些经验记录下来备查,本篇只是思路的整理,不涉及具体的使用. 大体的思路如下: 1.通过slow log查看 参考 http://www.cnb ...
- Android安全问题 静音拍照与被拍
之前写过一些android手机root之后的安全问题的(文章列表见末尾),其实我是想到哪就写到了,今天整理硬盘,发现一年之前写过一段代码,所以今天我们就一起来讨论一下. 注:这里不是讨论多nb的技术, ...
- 安装Ubuntu双系统系列——为Firefox安装Adobe Flash Player
使用环境:OS:Ubuntu 12.04 LTSBrowser: Firefox 12.0Adobe Flash Player: install_flash_player_11_linux.x86_6 ...
- android开发无障碍app
最近做一些为盲人提供服务的APP,还是挺有感触的,感谢手机和互联网的普及,他们的生活比以前丰富了很多. 通过读屏软件,盲人可以操作手机,上网浏览信息.读屏软件的工作原理很简单,就是读出屏幕上按钮.文本 ...
- PostgreSQL和MySQL like区别
前言:今天在PostgreSQL中使用like,字段类型是int,执行语句报错, 1.表结构:都是用sysbench工具产生的 postgres=# \d sbtest1; ...
- 【HDOJ】4343 Interval query
最大不相交集合的数量.思路是dp[i][j]表示已经有i个不相交集合下一个不相交集合的最右边界.离散化后,通过贪心解. /* 4343 */ #include <iostream> #in ...
- java之内部类与匿名内部类
Java 内部类 分四种:成员内部类.局部内部类.静态内部类和匿名内部类. 1.成员内部类: 即作为外部类的一个成员存在,与外部类的属性.方法并列. 注意:成员内部类中不能定义静态变量,但可以访问外部 ...
- poj 1259 Agri-Net(最小生成树)
题目:http://poj.org/problem?id=1258 题意:模板题 和2485差不多 就是求相连后的最小值. #include <iostream> #include< ...