简体   繁体   English

使用代码和框将前端(反应)连接到后端(节点)

[英]Connecting frontend (react) to backend (node) using codesandbox

I am using react, graphql and node.我正在使用 react、graphql 和 node。 Currently, my react codes are on codesandbox, whilst my server codes are on my local computer.目前,我的反应代码在 codeandbox 上,而我的服务器代码在我的本地计算机上。 How do i link up my frontend with my backend in this case?在这种情况下,我如何将前端与后端连接起来? Do i need to deploy my server codes onto heroku or digital ocean before i can link them?在链接它们之前,我是否需要将我的服务器代码部署到 heroku 或数字海洋上? I like to be able to test them first before deploying my codes我喜欢在部署我的代码之前先测试它们

I am also thinking of migrating my backend codes to codesandbox.我也在考虑将我的后端代码迁移到 codeandbox。 In this case, am i still able to link my frontend and backend codes in order to test them out before deploying to the hosting provider servers?在这种情况下,我是否仍然能够链接我的前端和后端代码,以便在部署到托管提供商服务器之前对其进行测试?

Thanks谢谢

If I have understood the question correctly; 如果我正确理解了这个问题;

If you are attempting to connect to codesandbox which by the looks of it is a hosted code editor for front end solutions, you would need to run your nodejs server on a PC connected to the internet. 如果您试图连接到codeandbox,从外观上看,它是前端解决方案的托管代码编辑器,则需要在连接到Internet的PC上运行nodejs服务器。

Within your router admin settings you would need to open the ports that your nodejs server is running on for that particular local address assigned to the PC. 在路由器管理员设置中,您需要为分配给PC的特定本地地址打开运行nodejs服务器的端口。

{your_ip_address}:{your_port}/api-route

When you need to make a call to you nodejs server. 当您需要调用nodejs服务器时。

Charlie is correct. 查理是对的。 I actually build my react frontend on codesandbox and connected to my node graphql backend on codesandbox too. 实际上,我在reactsandbox上构建了我的react前端,并也在codesandbox上连接了我的节点graphql后端。 Both must be running for that to work. 两者都必须运行才能正常工作。 Must enable cors too for both to connect. 也必须同时启用cors才能进行连接。 As im using apollo server 2, can pass a cors: true to the apollo server constructor. 即时通讯使用apollo服务器2时,可以将cors:true传递给apollo服务器构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Kubernetes 中将 React 前端连接到 Node JS 后端 - Connecting React Frontend to Node JS backend within Kubernetes 是否可以使用 Bunyan 将前端(React)错误记录到后端(Node JS)? - Is it possible to log frontend (React) errors to backend (Node JS) using Bunyan? React前端和Node后端之间的身份验证 - Authentication between React frontend and Node backend 将数据从Node后端传输到React前端 - Transfer data from Node backend to React frontend 用于后端的节点JS Express和用于前端的React JS - Node JS Express for backend and React JS for frontend 将反应前端与节点 js rest api 连接起来 - connecting react frontend with node js rest api 在 Kubernetes 中连接前端和后端 - Connecting Frontend and Backend in Kubernetes 通过使用节点作为后端并作为前端反应以什么方式将数据库表显示到材料ui表 - in what way display database table to material ui table by using node as backend and react as frontend 如何使用代理将页面从反应 js 前端转发到节点 js 后端 - How to forward page from react js frontend to node js backend using proxy 如何构建一个使用 React 构建的独立桌面应用程序,使用节点后端,并将前端和后端都包装在电子中作为桌面应用程序? - how to build a standalone desktop app built with react, using a node backend, and wrap both frontend and backend in electron as a desktop app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM