在Heroku上为node.js运行Ghost模块作为子目录

时间:2015-01-25 05:22:29

标签: express ghost-blog

我正在尝试将Ghost安装到我的节点应用程序中。我按照配置说明操作并运行,但是当我导航到blog子目录时,它只显示我的网站的主页。我正在传递Express应用程序实例以启动服务器。我做错了什么?

var ghost = require('ghost');
ghost().then(function (ghostServer) {
    app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
    ghostServer.start(app);
    
});

我在线阅读有关使用ngynx或apache运行Ghost并将其配置为执行某种代理操作的内容,但我并不真正理解所有这些内容。

2 个答案:

答案 0 :(得分:0)

这是app.js的一个工作版本,用于express和ghost子目录设置。注意你的快速路由如何包含在ghost.then()回调中。

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var ghost = require('ghost');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

ghost().then(function (ghostServer) {

    app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
    ghostServer.start(app);

    // view engine setup
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'jade');

    // uncomment after placing your favicon in /public
    //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
    app.use(logger('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(express.static(path.join(__dirname, 'public')));

    app.use('/', routes);
    app.use('/users', users);

    // catch 404 and forward to error handler
    app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
    });

    // error handlers

    // development error handler
    // will print stacktrace
    if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
          message: err.message,
          error: err
        });
      });
    }

    // production error handler
    // no stacktraces leaked to user
    app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
        message: err.message,
        error: {}
      });
    });
});

module.exports = app;

答案 1 :(得分:-1)

const ghost = require('ghost')
const express = require('express')
const path = require('path')
const { getSubDir } = require('./node_modules/ghost/core/server/services/url/utils')

const app = express()
ghost().then((ghostServer) => {
  app.use('/games', express.static(path.join(__dirname, 'games')))
  app.use(getSubdir(), ghostServer.rootApp)
  ghostServer.start(app)
})

此处包含最新的方法: https://docs.ghost.org/docs/using-ghost-as-an-npm-module