【问题标题】:Node.js, Express & Ghost Subdirectory URL parsing errorNode.js、Express 和 Ghost 子目录 URL 解析错误
【发布时间】:2014-09-21 00:21:06
【问题描述】:

欢迎回答有关在站点的子目录中服务 Ghost 的另一个问题!

我已经根据许多线程的详细信息(仍然没有文档......)和这个 Github 配置文件详细信息 (https://github.com/owenscott/hapi-ghost-proxy-example/blob/master/config.js) 设置了代理服务器。

我可以提供根页面,但不能让 Ghost 显示在子目录路由上。对于以下错误中到底发生了什么(当您导航到 url 时显示在浏览器中),我感到非常困惑:

    TypeError: Parameter 'url' must be a string, not undefined
   at Url.parse (url.js:107:11)
   at Object.urlParse [as parse] (url.js:101:5)
   at Object.common.setupOutgoing (C:\dev\projects\warpspeed\node_modules\http-proxy\lib\http-proxy\common.js:71:11)
   at Array.stream [as 3] (C:\dev\projects\warpspeed\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:109:14)
   at ProxyServer.<anonymous> (C:\dev\projects\warpspeed\node_modules\http-proxy\lib\http-proxy\index.js:80:21)
   at ghost.config (C:\dev\projects\warpspeed\server.js:23:8)
   at Layer.handle [as handle_request] (C:\dev\projects\warpspeed\node_modules\express\lib\router\layer.js:76:5)
   at next (C:\dev\projects\warpspeed\node_modules\express\lib\router\route.js:100:13)
   at Route.dispatch (C:\dev\projects\warpspeed\node_modules\express\lib\router\route.js:81:3)
   at Layer.handle [as handle_request] (C:\dev\projects\warpspeed\node_modules\express\lib\router\layer.js:76:5)

我猜这与通过 ghost 进行路由有关,详见我的 server.js 文件(如下)。

var express = require('express');
var ghost = require('ghost');
var httpProxy = require('http-proxy');
var path = require('path');

var app = express();
var proxy = new httpProxy.createProxyServer();

//routes
app.get('/', function(req, res){
    res.send('Coming soon...')
});
//ghost routes
app.get('/nowhammystop', function(req, res, next){
    proxy.web(res, req, {
        target: 'http://localhost:22889'
    });
});

//start Ghost
ghost({
    config: path.join(__dirname, 'node_modules/ghost/config.js')
});

var server = app.listen(12942);

有什么想法吗?

【问题讨论】:

    标签: javascript node.js express ghost-blog node-http-proxy


    【解决方案1】:

    我不确定这是否最近发生了变化,但正确的做法是现在:

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

    查看this out了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 2017-09-03
      • 1970-01-01
      • 2017-06-17
      • 1970-01-01
      相关资源
      最近更新 更多