简体   繁体   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?

I hope someone out there can help me out!我希望有人可以帮助我!

I have an Angular Universal app which I have deployed to Google App Engine.我有一个已部署到 Google App Engine 的 Angular 通用应用程序。

I have an app which is running on the default instance of the GAE and it has its own custom domain that I've configured.我有一个在 GAE 的默认实例上运行的应用程序,它有自己配置的自定义域。

So now I want to run a separate node app which is basically just an express server with a mail api endpoint (/api/sendmail) to send mails.所以现在我想运行一个单独的节点应用程序,它基本上只是一个带有邮件 api 端点(/api/sendmail)的快递服务器来发送邮件。

This endpoint will be running on http://localhost:3000/api/sendmail.此端点将在 http://localhost:3000/api/sendmail 上运行。 Below are all my files.以下是我所有的文件。

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

But it doesn't seem to run the following.但它似乎没有运行以下。 It doesn't run the console log?它不运行控制台日志?

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

My package.json has these scripts我的 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 file has this Proxy.conf.json 文件有这个

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

App.yaml App.yaml

runtime: nodejs10

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

dispatch.yaml dispatch.yaml

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

This is my app.yaml which runs the node app on it's own service这是我的应用程序。yaml 在自己的服务上运行节点应用程序

runtime: nodejs10
service: servicename

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

My node app has one file: nodemailer.js我的节点应用程序有一个文件:nodemailer.js

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

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

Please let me know if anyone needs more info.如果有人需要更多信息,请告诉我。 Please check if you see something wrong.请检查您是否发现有问题。

I am seeing that you're using SSR in your Angular app.我看到您在 Angular 应用程序中使用了 SSR。 I think you need to modify your server.ts file.我认为您需要修改 server.ts 文件。 Please check below code for an example:请检查以下代码以获取示例:

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

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

相关问题 将 Angular Universal 9 部署到 Google App Engine - Deploying Angular Universal 9 to Google App Engine 如何在Google Compute Engine上部署节点应用程序? - How do I deploy a node app on Google Compute Engine? 如何使用 app.yaml 文件为 App Engine / Node.js 应用程序运行本地服务器? - How do I run a local server for an App Engine / Node.js app with an app.yaml file? 在 Google Cloud App Engine 上部署 Angular 通用应用程序时出错 - Error when deploying Angular Universal app on Google Cloud App Engine 如何在Google App Engine中构建API和前端应用程序? - how should I architecture an API and front app in Google App Engine? Google App Engine Standard Node JS 如何运行构建脚本? - Google App Engine Standard Node JS how to run build script? 构建节点前端和后端并将其部署到 Google App Engine - Structuring and deploying node frontend and backend to Google App Engine 如何在 AWS EC2 上使用 node.js 后端在 Nginx 上运行 React App? - How do I Run React App on Nginx with a node.js backend on AWS EC2? 如何设置一个具有节点后端的Angular 8应用并将其托管在Firebase上? - How do I set up an Angular 8 app that has a node backend and host it on firebase? 将Angular 6 Universal部署到GCP App Engine - deploying Angular 6 Universal to GCP App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM