简体   繁体   English

将Angular Universal应用程序与自定义Node.js / Express Server捆绑在一起

[英]Bundle Angular Universal app with custom nodejs/express server

I just want to know the correct way to serve an angular universal app with an existing nodejs/express server that talks to a Mongodb database and serves data with an "/api/*" route for example. 我只想知道使用现有的nodejs / express服务器与Mongodb数据库对话并使用“ / api / *”路由提供数据的角度通用应用程序的正确方法。

So is it to have the universal app have its own node/express server as explained here https://angular.io/guide/universal and just merge that with the existing node/express server with route configuration as done here Serve angular universal app with NodeJS/ExpressJS back-end and allow both the custom node/express server and the universal apps express server have different ports (because i assume that is how they will be able to co-exist in production) 因此,它是有普遍的应用程序有它自己的节点/ Express服务器按如下说明https://angular.io/guide/universal ,只是合并与现有节点/表达与路由配置服务器为这里所做即成角通用的应用程序与NodeJS / ExpressJS后端配合使用,并允许自定义节点/表达服务器和通用应用程序表达服务器具有不同的端口(因为我认为这是它们将能够在生产环境中共存的方式)

Or do we use the custom node/express server as the server for the universal app with proper configuration. 还是我们使用自定义节点/表达服务器作为具有适当配置的通用应用程序服务器。

To serve angular app with node server first you need to build the app just run the below command 要将角度应用程序与节点服务器一起提供,您需要构建该应用程序,只需运行以下命令

ng build

And then add two lines of code in your node server file as 然后在您的节点服务器文件中添加两行代码,如下所示:

app.use(express.static(__dirname + '/dist'))
app.use(function(req, res) {
res.sendFile(__dirname + '/dist/index.html')
})

And after that you can run node server and the default entry index html file will open when you hit the host. 然后,您可以运行节点服务器,并且在您击中主机时将打开默认的条目索引html文件。

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

相关问题 我需要帮助向 nodejs express 服务器(Angular Universal)中的外部 API 发出 API 请求 - I need help making an API request to an external API in nodejs express server (Angular Universal) NodeJS Express Rest API APP进入Angle 5项目 - NodeJS express rest API APP into angular 5 project 从 nodejs express 发送响应到 angular 应用程序 - send response from nodejs express to angular app 将Angular 5 + Nodejs Express应用程序部署到Heroku - Deploy Angular 5 + Nodejs Express app to Heroku 在node.js Express服务器上部署angular Universal - deploying angular universal on node.js express server 未在Node.js Express应用中定义的自定义模块 - custom module not defined in nodejs express app 与NodeJS / ExpressJS后端一起提供角度通用应用程序 - Serve angular universal app with NodeJS/ExpressJS back-end 如何在nodejs Angular Universal web应用程序上强制域到https? - How to force domain to https on nodejs Angular Universal web app? Angular Universal - NodeJS 服务器对动态路由的 HTML 的响应 - Angular Universal - NodeJS Server's Response to HTML for Dynamic Routes 在 App Engine 上使用 Angular Universal 进行服务器渲染的 Angular 5 应用程序 - Angular 5 app with server rendering with Angular Universal on App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM