谷歌应用引擎Angular+Express总是404刷新



我在谷歌应用程序引擎上有一个angular和expressJS应用程序,每次刷新时都会出现404错误页面。我看到人们通过在他们的app.yaml文件中使用处理程序来解决这个问题,但任何这样做的尝试都会破坏我的应用程序——以前Express为Angular文件提供服务时,有人必须这样做吗?

GAE上的项目文件夹结构./build ExpressJS后端逻辑./public Angular 9前端(prod-build(

我的Express服务器是以下

const app = express()
app.set('views', 'cloud/views')  // Specify the folder to find templates
app.set('view engine', 'ejs')    // Set the template engine
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use('/backend', api)
// Serve static assets from the /public folder
app.use('/', express.static('./public'))

我的angular应用程序由feathersjs的express服务时出现了这个问题。添加这样的东西可能会解决问题:

app.use('/', express.static('./public', { redirect: false }));
app.get('*', function (req, res, next) {
res.sendFile(path.join('./public', 'index.html'));
});

最新更新