如何在任何在线服务器中部署Spring框架后端和Angular 2前端应用程序? [英] How to deploy Spring framework backend and Angular 2 frontend application in any online server?

查看:177
本文介绍了如何在任何在线服务器中部署Spring框架后端和Angular 2前端应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的操作方式有误,请更正.

Please correct if the way I am doing is wrong.

在我的Web应用程序中,我没有使用jsp页面来开发用户界面.相反,我使用的是html,css和Angular 2,前端项目结构与后端分离.

In my web application I am not using jsp pages for developing user interface. Instead I am using html, css and Angular 2 and front-end project structure is separated from back-end.

尽管我能够使用Angular CLI开发一个简单的项目,该项目由SpringMVC后端提供服务.前端使用端口4200,后端在端口8080上运行.我设法从Angular 2接收并处理对SpringMVC的请求.在本地模式下,它们运行良好,现在我想将它们托管在实时服务器上.

Although I am able to develop a simple project using Angular CLI which is served by SpringMVC back-end. Front-end is using port 4200 and backend is running on port 8080. I have managed to take and serve request from Angular 2 to SpringMVC. In local mode these are working perfectly, now I want to make them host on a live server.

如何分别发布SpringMVC后端和Angular 2前端但在同一域上运行?我没有使用SpringBoot,前端和后端也位于单独的文件夹中.我不想将两者合并在同一个项目结构中并生成war文件并进行部署.

How to publish SpringMVC back-end and Angular 2 front-end separately but running on same domain? I am not using SpringBoot also front-end and back-end are in separate folders. I do not want to combine both in same project structure and generate a war file and deploy.

开发SpringMVC后端和Angular-2后端并将其部署在在线服务器中的最佳实践是什么?

What is the best practice for developing SpringMVC back-end and Angular-2 back-end and deploying them in online server?

推荐答案

我发现最有效的方法是将nginx作为静态文件服务器和spring应用程序的正向代理运行.

What I've found works best is running nginx as a static file server and a forward proxy for the spring app.

通常我使用angular-cli代理使/api/转到 http://localhost:8080

usually I use the angular-cli proxy to make /api/ go to http://localhost:8080

这意味着对 http://localhost:3000/api/ **的调用会传递给 http://localhost:8080/api/ .而且由于您在同一个域中,所以我们可以简单地调用/api/

that means that calls to http://localhost:3000/api/** get passed to http://localhost:8080/api/. And since you are on the same domain we can simply call /api/

这篇关于如何在任何在线服务器中部署Spring框架后端和Angular 2前端应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆