[英]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.