[英]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.