我正在尝试构建一个简单的WebSockets应用程序,node.js作为服务器。为了创建一个WebSocket连接,我编写了以下内容:
const url = 'ws://localhost:8080'
const connection = new WebSocket(url)但我不想硬编码URL。我能从我的服务器收到它吗?
发布于 2021-03-06 12:20:18
现有备选方案:
Webpack/卷取/雪包- https://dev.to/sanfra1407/how-to-use-env-file-in-javascript-applications-with-webpack-18df的
- You can define a some `.env` and define address of server
- Use `dotenv` or something another library on backend side to receive variable
- Use Webpack/Rollup/Snowpack on frontend side to build frontend with defined address of server
- It will allow to change address of server in one placehttps://medium.com/jspoint/a-beginners-guide-to-react-server-side-rendering-ssr-bf3853841d55 (服务器端渲染)-
- You can provide address of server from backend to frontendhttps://stackoverflow.com/questions/66505298
复制相似问题