Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: fetch is not defined #7

Open
CharlseYuan opened this issue Oct 15, 2022 · 6 comments
Open

ReferenceError: fetch is not defined #7

CharlseYuan opened this issue Oct 15, 2022 · 6 comments

Comments

@CharlseYuan
Copy link

image

@yuaanlin
Copy link
Member

fetch 是浏览器的才能使用的功能, API 路由的运行环境是 nodejs 后端,所以无法使用 fetch

建议的做法是将文章数据保存于数据库中,然后在 API 路由透过 Prisma 去数据库查询并返回。

@CharlseYuan
Copy link
Author

image

执行到 let post = await redis.get('post-' + req.params.postId),就报上面的错了

@yuaanlin
Copy link
Member

image

执行到 let post = await redis.get('post-' + req.params.postId),就报上面的错了

可以先把 Redis 缓存这部分逻辑拿掉

@CharlseYuan
Copy link
Author

拿掉执行就没问题了

@CharlseYuan
Copy link
Author

Redis 缓存这部分不会,网上没找到相关的解释

@yuaanlin
Copy link
Member

Redis 缓存是作为一个提速的效果,避免每次请求 API 路由都要从 MongoDB 查询数据,造成网页访问速度下降

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants