如何使用React-Router和Express后端返回有效的JSON响应? [英] How can I return a valid JSON response with React-Router and an Express backend?

查看:88
本文介绍了如何使用React-Router和Express后端返回有效的JSON响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与此 https://socialmaya.com/u/real 来查看JSON.但除非我访问 http://socialmaya.com:5000/actors/,否则无法获得实际的JSON响应真正的,这就是React所称的.

I have a setup similar to the one in this tutorial. How can I render JSON alone (no HTML) without having to specify the port number for the route specified in index.js? Within my own setup, I can view JSON by visiting https://socialmaya.com/u/real but can't get an actual JSON response unless I visit http://socialmaya.com:5000/actors/real, which is what's being called by React.

这是我的代码,该代码试图为使用以下代码构建的社交网络实现ActivityPub API MERN堆栈.可以在此处找到我的Nginx配置.

Here is my code which is an attempt to implement an ActivityPub API for a social network built using the MERN stack. My Nginx configuration can be found here.

推荐答案

在Nginx内部将其传递给上游之前重写URL可以解决我的问题:

Rewriting the URL before passing it upstream within Nginx solved my problem:

location / {
    rewrite ^/u/(.*)$ /actors/$1 last;
    proxy_pass http://localhost:5000;
}

这篇关于如何使用React-Router和Express后端返回有效的JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆