简体   繁体   English

Node.js,Express和Ghost子目录URL解析错误

[英]Node.js, Express & Ghost Subdirectory URL parsing error

Welcome to another question about serving Ghost on a subdirectory of a site! 欢迎来到另一个有关在网站的子目录上提供Ghost的问题!

I've set up a proxy server as per many threads have detailed (still no documentation....) and this Github profile details ( https://github.com/owenscott/hapi-ghost-proxy-example/blob/master/config.js ). 我已经根据许多线程的详细信息设置了代理服务器(仍然没有文档。。。)和这个Github配置文件的详细信息( https://github.com/owenscott/hapi-ghost-proxy-example/blob/master /config.js )。

I can serve the root page, but can't get Ghost to display on the subdirectory route. 我可以提供根页面,但不能让Ghost显示在子目录路由上。 I'm fairly baffled as to what exactly is happening in the following error (displayed in the browser when you navigate to the url): 对于以下错误(在您导航至该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)

I'm guessing it has something to do with the routing through ghost, as detailed in my server.js file (below). 我猜测这与通过幽灵进行路由有关,如我的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);

Any ideas? 有任何想法吗?

I am not sure if this has recently changed, but the proper way to do this is now: 我不确定这是否最近有所改变,但是现在可以使用的正确方法是:

var ghost = require('ghost'),
express = require('express'),
parentApp = express();

ghost().then(function (ghostServer) {
    parentApp.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
    ghostServer.start(parentApp);
});

Check this out for more information. 查看此以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM