大佬教程收集整理的这篇文章主要介绍了在我的主Node.js应用程序的子目录中运行Ghost,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我按照这里的说明操作:
https://github.com/TryGhost/Ghost/wiki/Using-Ghost-as-an-NPM-module
随着使用Ghost作为npm模块的新增功能,我还需要Nginx还是Apache?截至目前,我的主站点运行在localhost:3000上,Ghost实例运行在localhost:2368上.
我已经尝试对指令中所述的部分代码进行各种修改,但是我还没有成功.
//app.js,is there a specific place to put this? var ghost = require('ghost'); ghost().then(function (ghostServer) { ghostServer.start(); }); //config.js development: { url: 'http://localhost:3000/blog',database: { client: 'sqlite3',connection: { filename: path.join(__dirname,'/content/data/ghostdev.db') },debug: false },server: { host: '127.0.0.1',port: '2368' },paths: { contentPath: path.join(__dirname,'/content/'),} },//index.js ghost().then(function (ghostServer) { parentApp.use(ghostServer.config.paths.subdir,ghostServer.rootApp); // Let ghost handle starTing our server instance. ghostServer.start(parentApp); }).catch(function (err) { errors.logErrorAndExit(err,err.context,err.Help); });
编辑:我能够使用http-proxy路由流量但是它将它路由到localhost:2368 / blog(这不存在)有关如何防止这种情况的任何想法?
var httpProxy = require('http-proxy'); var blogProxy = httpProxy.createProxyServer(); var ghost = require('ghost'); var path = require('path'); // Route /blog* to Ghost router.get("/blog*",function(req,res,next){ blogProxy.ws(req,{ target: 'http://localhost:2368' }); });
在尝试我的建议之前,您应该撤消使用httpproxy所做的任何更改.
对我来说似乎有用的是将index.js中的代码直接放入app.js文件中,而不是放在那里.您将需要添加ghost errors变量并将parentApp重命名为您的应用程序的名称,我将其称为yourAppName,因此它很清楚,但我的只是app.所以在app.js里面你可以放:
var yourAppName = express(); var ghost = require('ghost'); var ghosterrors = require('ghost/core/server/errors') ghost().then(function(ghostServer) { yourAppName.use(ghostServer.config.paths.subdir,ghostServer.rootApp); ghostServer.start(yourAppName); }).catch(function(err) { errors.logErrorAndExit(err,err.Help); });
您可能已经在app.js中声明了ghost和express变量,因此您不需要添加这些行.
以上是大佬教程为你收集整理的在我的主Node.js应用程序的子目录中运行Ghost全部内容,希望文章能够帮你解决在我的主Node.js应用程序的子目录中运行Ghost所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。