【问题标题】:Google App Engine Angular + Express always 404 on refreshGoogle App Engine Angular + Express 在刷新时总是 404
【发布时间】:2020-08-14 14:34:32
【问题描述】:

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

GAE 上的项目文件夹结构 ./build ExpressJS 后端逻辑 ./public Angular 9 前端(产品构建)

我的快递服务器如下

...

    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 express google-app-engine


    【解决方案1】:

    feathersjs 的 express 提供的 Angular 应用程序出现此问题。 添加这样的东西可能会解决它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 2017-06-12
      • 2012-05-15
      • 2015-09-21
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      相关资源
      最近更新 更多