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

feat: deploy on AWS Lambda #703

Merged
merged 6 commits into from
May 22, 2024
Merged

feat: deploy on AWS Lambda #703

merged 6 commits into from
May 22, 2024

Conversation

wzyboy
Copy link
Contributor

@wzyboy wzyboy commented May 21, 2024

考虑到 Vercel 和 Netlify 都是运行在 AWS Lambda 上,我尝试直接将 Twikoo 部署到 AWS Lambda 上。

我试着将 Netlify 的兼容代码改了一份,放到 Lambda 上跑了一下,能工作,但似乎拿不到评论者的 IP 地址。

我的 JavaScript 水平不精,找不到问题所在。根据 AWS 文档,IP 地址存储于 requestContext.http.sourceIp 里,我也把这段设置到 TWIKOO_IP_HEADERS 里了,但服务端依然拿不到地址。

是因为只支持 IPv4 吗?

@wzyboy wzyboy changed the title feat: aws-lambda compat code feat: deploy on AWS Lambda May 21, 2024
Copy link
Member

@imaegoo imaegoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据您提供的文档,您需要将requestContext对象放入request对象,并设置TWIKOO_IP_HEADERS为requestContext.http.sourceIp,请测试这样是否能够获取到IP地址

src/server/aws-lambda/src/index.js Show resolved Hide resolved
src/server/aws-lambda/src/index.js Show resolved Hide resolved
@wzyboy
Copy link
Contributor Author

wzyboy commented May 21, 2024

@imaegoo 感谢指导!

我又仔细查了下,发现其实服务端是可以拿到 IP 地址的,但在管理界面的 IP 归属地查询不支持 IPv6,因此我错误地以为没有 IP 地址。

我用 curl -4 提交评论,是能成功显示出 IP 归属地的。

@wzyboy wzyboy requested a review from imaegoo May 21, 2024 07:09
@imaegoo imaegoo merged commit 0cfdd9c into twikoojs:main May 22, 2024
1 check passed
@imaegoo
Copy link
Member

imaegoo commented May 22, 2024

感谢贡献

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

Successfully merging this pull request may close these issues.

2 participants