繁体   English   中英

如何在 Google App Engine 上为后端 api 运行 Angular 通用应用程序和单独的节点应用程序?

[英]How do I run an Angular Universal app and separate node app for backend api on Google App Engine?

我希望有人可以帮助我!

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

我有一个在 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

这是我的应用程序。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");
}

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

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

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

暂无
暂无

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

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