简体   繁体   English

如何通过Express在Openshift上提供静态文件?

[英]How to serve static files on Openshift from Express?

I need an Openshift person to answer this. 我需要一个Openshift人来回答这个问题。 Local server working serving files from /static folder on root. 本地服务器工作在根目录上的/ static文件夹中提供文件。 Once ported up to Openshift, "404 not found". 移植到Openshift后,“ 404未找到”。 There is something in Openshift that is changing my routes. Openshift中有一些东西正在改变我的路线。 I'm using the lines: 我正在使用这些行:

 const repoDir = env.OPENSHIFT_REPO_DIR || __dirname;
 app.use(express.static(repoDir + '/static'));

What step am I missing? 我想走哪一步?

I am user of OpenShift‎ . OpenShift的用户。

Recently I have came across the similar issue. 最近,我遇到了类似的问题。

Please refer the below to check if it resolves the issue. 请参考以下内容,检查是否可以解决问题。

1. Check if you get the below error. 1.检查是否出现以下错误。

TypeError: Object #<ServerResponse> has no method 'sendFile'
- try Upgrading expressJS version

2. Use the below approach to serve the static files including js. 2.使用以下方法来提供包括js在内的静态文件。 Working sample 工作样本

<code>
  app.use(express.static(path.join(__dirname, '/public')));

  app.get('/', function(req, res){
   res.sendFile(path.join(__dirname, '/views/index.html'));
  });
</code>

express - version is 4.14.0 express-版本为4.14.0

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

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