【问题标题】:How do I run an Angular Universal app and separate node app for backend api on Google App Engine?如何在 Google App Engine 上为后端 api 运行 Angular Universal 应用程序和单独的节点应用程序?
【发布时间】:2020-08-22 18:21:03
【问题描述】:

希望有人能帮帮我!

我有一个已部署到 Google App Engine 的 Angular Universal 应用程序。

我有一个在 GAE 的默认实例上运行的应用程序,它有自己配置的自定义域。

所以现在我想运行一个单独的节点应用程序,它基本上只是一个带有邮件 api 端点 (/api/sendmail) 的快速服务器来发送邮件。

此端点将在 http://localhost:3000/api/sendmail 上运行。以下是我所有的文件。

当我点击端点 /api/sendmail,并使用 gcloud app logs tail -s servicename 检查日志时,它会注销 app.listen(3000, () => { console.log("The server started on port 3000");});

但它似乎没有运行以下内容。它不运行控制台日志?

app.post("/api/sendmail", (req, res) => {
    console.log("Got Request");
}

我的 package.json 有这些脚本

"start": "node dist/server",
"deploy": "ng build --prod && npm run build:ssr && gcloud app deploy --quiet && gcloud app deploy dispatch.yaml --quiet",

Proxy.conf.json 文件有这个

{
    "/api": {
        "target": "http://localhost:3000",
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": {
            "^/api": ""
        }
    }
}

App.yaml

runtime: nodejs10

handlers:
    - url: /.*
      secure: always
      redirect_http_response_code: 301
      script: auto

dispatch.yaml

dispatch:
    - url: "*/api/*"
      service: lunr-app-backend

这是我的 app.yaml,它在自己的服务上运行节点应用程序

runtime: nodejs10
service: servicename

handlers:
  - url: /api/.*
    secure: always
    redirect_http_response_code: 301
    script: auto

我的节点应用有一个文件:nodemailer.js

app.listen(3000, () => {
    console.log("The server started on port 3000");
});

app.post("/api/sendmail", (req, res) => {
    console.log("Got Request");
}

如果有人需要更多信息,请告诉我。请检查您是否发现有问题。

【问题讨论】:

    标签: node.js angular angular-universal


    【解决方案1】:

    我看到您在 Angular 应用程序中使用了 SSR。我认为您需要修改 server.ts 文件。请查看以下代码以获取示例:

    https://github.com/Angular-RU/angular-universal-starter/blob/d0b4b2a05a9d32c52562cf364261669bffde873c/server.ts#L113

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-12
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 2014-11-24
      • 2013-05-24
      相关资源
      最近更新 更多