English 中文(简体)
如何在“npm 跑道建造”后改变APIC的港口
原标题:How to change the port in API after `npm run build`
client/
  scriptWhichMakesApiCall/
         await axios.get("http://localhost:${REACT_PORT}/api/product-category");

Doing "npm run build". REACT_PORT value is baked into build.

server/
      express which dynamically assigns itself some PORT.

我的法规基础可以作些什么修改,以便我的建筑反应使我所说的话听起来的准确港?

I have hard coded the PORT number in react app. Build it. Also hard coded the PORT number in express. This doesn t seem robust.

问题回答

• 确保建立你明确的服务器港。 可以通过在你明确的服务器入口档案中添加以下代码这样做:

const port = process.env.PORT || 3000; /*set 3000 to your desired port number*/

然后可以在你的反应中利用港口,将其添加到我们的轴心中。

await axios.get("http://localhost:3000/api/product-category");

任何人都 st着这个问题。

仅使用相对的URL,如/api/product- category 。

这样,它将自动使用从该网页上服务的同一东道名称和港口。 因此,在建造反应堆时,没有使用任何补给。





相关问题
VS 2008 : How to publish with out DLLs?

I have developed a web application in Visual Studio 2008 and want to publish it in to the production server. I see a publish option there.But its producing files with DLL. I dont want to publish only ...

Apache: Deploying a new site to the server

I have a site currently live on a domain. I would like to switch it to a new site, that is currently in a password protected sub directory on this server. I have a "Site Maintenance in Progress" page....

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Pylons deployment questions

I m a beginner with Pylons and I ve mostly developed on my localhost using the built-in web server. I think it s time to start deployment for my personal blog, I have a Debian Lenny server with ...

Do I want Publish or Release Build in VB.net?

I wrote a little (like 40 lines little) Winforms application with VB.net in Visual Studio 2010. Now I ve released the code as a Google Code project. It s easy for a developer to get the source but I d ...

Need advice on my PHP development solution

Here is how our current php development solution is set up: Each developer work on their local machine. Each developer commit their change to a common SVN server (intranet). A commit hook upload the ...

loading from JAR files during deployment vs development

when i am loading some data into my java program, i usually use FileInputStream. however i deploy the program as a jar file and webstart, so i have to use getRessource() or getRessourceAsStream() to ...

热门标签