1

我一直在使用Node.js Google App Engine几个月,并且一直使用express.static解决方案来访问静态文件公用文件夹,当我部署我的node.js应用程序。Node.js应用程序404错误Google App Engine中的公共目录灵活的生产环境

对于一些(对我来说不是那么明显)的原因,我很难在Google灵活生产环境中最近得到这个工作。在我的本地开发环境中,一切都很好。

为了缩小问题我创建了一个非常基本的测试程序在这里列出:

'use strict' 

const express = require('express') 
const app  = express() 
const path = require('path') 
const os  = require('os') 
const PORT = process.env.PORT || 8080 
const ENV  = process.env.NODE_ENV 

//app.use(express.static('public')) 
//app.use(express.static(path.resolve(__dirname, 'public'))) 
app.use(express.static(path.join(__dirname, 'public'))) 

app.listen(PORT,() => { 
console.log(`SYSTEM: App listening on port ${PORT}`) 
console.log(`SYSTEM: Press Ctrl+C to quit.`) 
}) 

app.get('/', (req,res) => { 
res.status(200).send('\ 
    <h1>TEST app.use(express.static("public")) in Google Cloud Flexibel App  Engine environment </h1>\ 
    <hr/>\ 
    <h4>YAML settings: runtime: nodejs env: flex</h4>\ 
    <h4>HOST   : '+`${os.hostname()}`+'</h4>\ 
    <h4>PORT   : '+`${PORT}`+'</h4>\ 
    <h4>__dirname : '+`${__dirname}`+'</h4>\ 
    <h4>mountpath : '+`${app.mountpath}`+'</h4>\ 
    <h4>env   : '+`${ENV}`+'</h4>\ 
    <h4>path resolved: '+`${path.resolve(__dirname, 'public')}`+'</h4>\ 
    <h4>path joined : '+`${path.join(__dirname, 'public')}`+'</h4>\ 
    <hr/>\ 
    <h2>If you see me <img src="./HB.png"> you can access "./HB.png" in the "public" directory.</h2>\ 
    <h2>If you see me <img src="/HB.png"> you can access "/HB.png" in the "public" directory.</h2>\ 
    <h2>If you see me <img src="HB.png"> you can access "HB.png" in the "public" directory.</h2>\ 
    <hr/>\ 
') 
}) 

我试过的express.static设置的各种设置(见那些注释掉)。但每次部署后使用 gcloud应用部署 Google生产我得到404(也在谷歌日志)。在当地的开发环境一切都很好。

这里的生产环境的输出:

Production

而这里的本地开发环境的输出:

Local Development

正如你可以在谷歌看到督促图片链接HB.png坏了。在Google日志中出现404。

有没有人有线索?提前致谢 !

回答

0

奇怪的是,我通过重新安装Google Cloud SDK解决了这个问题。

相关问题