首页 > 解决方案 > 在 Electron 应用程序的生产环境中表达本地主机 URL

问题描述

我正在构建一个使用 Express 服务器来允许访问本地文件系统的 Electron 应用程序。

在本地开发时,Express 使用localhost:3000默认 URL,并且 React 前端和 Express/Node 服务器之间的所有 API 交互都localhost在 URL 中发送,如下所示:

// Call getHistory in server.js
fetch(`http://localhost:3000/getHistory?file=${file}`)
.then((data) => data.json())
.then(function(data) {
    this.resizeImage(data.file);
})
.catch(function(error) {
    console.log(error);
});

我不明白什么时候需要打包应用程序以进行生产,我该如何处理 localhost url?

我假设该应用程序不应在端口上运行,:3000因为其他应用程序可能已经在使用此端口。

标签: node.jsreactjsexpresslocalhostelectron

解决方案


推荐阅读