在两个单独的文件夹中使用客户端和服务器将节点应用程序部署到heroku [英] Deploying node app to heroku with client and server in two separate folders

查看:61
本文介绍了在两个单独的文件夹中使用客户端和服务器将节点应用程序部署到heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多研究,但我似乎还不太愿意为此做准备.

I've done a bunch of research and I can't quite seem to wrap my head around this.

我已经构建了一个应用.客户端是使用Vue-cli构建的,并在客户端文件夹的port 8080上运行,服务器在port 8081上的单独服务器文件夹中运行.本质上,我有这个:

I've built an app. The client was built with Vue-cli and runs on port 8080 from a client folder, and the server from a separate server folder on port 8081. In essence, I have this:

client
    - package.json
    - node_modules
    - src
    - build
    - index.html

server
    - package.json
    - node_modules
    - app.js
    - auth.js

我不确定如何解析文件夹结构,以便将其部署到Heroku.

I'm unsure of how to resolve the folder structure so that I can deploy this to Heroku.

根据我所做的大量研究和答案(当然是很老的帖子),一个建议是将两者结合起来,但是我将如何解析每个文件夹(客户端和服务器)中的两个package.json文件?我要合并它们吗?

According to a bunch of research I've done and this answer (admittedly quite an old post), one suggestion is to combine the two, but how would I resolve the two package.json files that I have in each folder (client and server)? Do I merge them?

另一个建议是创建两个单独的Heroku应用.然后可以将axios baseURL设置为app_name.herokuapp.com?

Another suggestion is to create two separate Heroku apps. I can then set my axios baseURL to app_name.herokuapp.com?

通常认为这两者中的哪一个是理想的解决方案?我真的被困在这里...

Which of the two is generally considered the ideal solution? I'm really stuck here...

推荐答案

据我所知,如今进行两次部署是开发许多开发人员的大型项目最常用的解决方案,其中一部分是vue.js的前端来自远程api的数据,这是您的后端和第二次部署.确实,您必须将baseURL更改为app_name.herokuapp.com.此​​外,您可能还必须启用CORS.

As far as I know nowadays making two deploys is the most used solution for big projects evolving many devs, in one part your frontend with vue.js that will fetch the data from a remote api which is your backend and second deploy. Exactly, you will have to change your baseURL to app_name.herokuapp.com Also you will probably will have to enable CORS.

如果您想尝试新事物,我建议您为前端部署尝试 surge ;)如此简单且方便很快!

Also if you want to try new things I recommend you try surge for your front deployment ;) so easy and so fast!

也许您已经知道了,但是,Heroku设置了它自己的端口,因此您将需要创建一个.env文件并通过ssh或在Heroku仪表板中手动进行分配.

Maybe you already know it but, Heroku sets it's own ports so you will need to create a .env file and assign it via ssh or manually in the Heroku dashboard.

这篇关于在两个单独的文件夹中使用客户端和服务器将节点应用程序部署到heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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