本文介绍了如何以及在何处部署同时需要两个服务器的Angular 8 Web应用程序[MEAN stack]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序.这是一个博客和问答网站,使用MEAN堆栈通过 Mongodb 进行CRUD操作.在此之前,我已经部署了许多用 react angular 构建的应用程序,其中仅需要一台服务器,即 npm start ,因为没有后端服务器代码.但是这次我决定将后端代码与前端代码分开. server.js 在另一个文件夹中,并在 port:3000 上运行,而应用程序在 localhost:4200 上运行.我正在使用 cors 进行跨源通信.该项目是开源的.我已经在github上上传了.这是回购.考虑所有这一切.请至少给我一些如何部署此项目的提示.我也准备购买域名和 VPS .

I have a web application. It's a blog and question-answer website made with MEAN stack making CRUD operations using Mongodb. Before this I have deployed many applications built in react and angular wherein only one server was required i.e. npm start as there was no back-end server code. But this time I decided to keep my back-end code separate from my front-end code. server.js is in a different folder and is running on port:3000, while application is running on localhost:4200. I am using cors for cross origin communication. The project is open source. I have uploaded on github. Here's the repo. Consider it all yours. Please at least give me some hint how to deploy this project. I'm ready to buy domain and VPS also.

PS:请通过 README.md

推荐答案

  1. 您必须使用 ng build --prod 来编译开发文件.
  2. 然后,您需要设置node.js文件.请检查代码
  3. 然后仅将所有服务器文件和dist文件夹上载到服务器.

  1. You have to use ng build --prod for compile your development file.
  2. Then you need to setup your node.js file.please check the code
  3. Then just upload all the server files and dist folder to server.

并使用 pm2 运行服务器.您必须从安装该链接

And run the server using pm2 . You have to install it from please check this link

就是这样.现在,您的 fron-end back-end 在您的特定 port 上一起运行.

That's it. Now your fron-end and back-end run together on your specific port.

这篇关于如何以及在何处部署同时需要两个服务器的Angular 8 Web应用程序[MEAN stack]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:11