这是indexloc提供的服务,不要输入任何密码
Skip to content

避免公开 根路径 / 导致被其它人滥用 #38

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

Merged
merged 52 commits into from
Aug 12, 2023

Conversation

crazypeace
Copy link

在访问 根路径 / 时,返回404
只有在访问一个秘密路径时,才返回正常的使用页面

修改说明:
https://zelikk.blogspot.com/2022/07/url-shorten-worker-hide.html

部署教程:
https://zelikk.blogspot.com/2022/07/url-shorten-worker-hide-tutorial.html

xyTom and others added 30 commits December 5, 2020 23:05
添加对Random_Key 是否重复的检查,防止恰好生成了相同的6位随机字符串,之前的 URL 就被替换的情况发生
完善对URL合法性的检查
if 嵌套的等效写法
* Add API document

This is the API document for Url-Shorten-Worker.

* Update README.md
Add a config which allow you to customize some behaviour of the Url-Shorten-Worker. You can set custom theme by modify the config.theme. There are two theme you can choose default and urlcool. Set config.theme to "theme/urlcool" to use the urlcool theme. Leave the config.theme to be blank to use the default theme. Also you can use config to control the CORS behaviour and HTTP Referer header.
Fix some issues
…ble. (xyTom#30)

Co-authored-by: David <davvido51gmail.com>
直接访问域名返回404。在KV中设置一个entry,保存秘密path,只有访问这个path才显示使用页面。
This reverts commit 60f2d7e.
@crazypeace
Copy link
Author

@crazypeace
Copy link
Author

@xyTom xyTom changed the base branch from main to crazypeace August 12, 2023 18:24
@xyTom xyTom merged commit 9cf4d92 into xyTom:crazypeace Aug 12, 2023
@xyTom
Copy link
Owner

xyTom commented Aug 12, 2023

感谢贡献代码,由于新增功能较多,故我觉得可以成为完全独立的一个版本,所以创建了一个新的分支用于合并。

目前Url-Shorten-Worker共有两个版本:

原版:https://github.com/xyTom/Url-Shorten-Worker/
crazypeace 修改版: https://github.com/xyTom/Url-Shorten-Worker/tree/crazypeace

用户可根据自身情况选择需要的版本进行部署

再次感谢crazypeace贡献代码,也欢迎其他的朋友提交pull request贡献代码!

@crazypeace
Copy link
Author

你好!
其它的功能性的东西, 合不合并看个人对项目的定义和取舍. 但是有一个地方, 关于API的接口的定义和使用方法, 想和你探讨一下.

你的代码, 不管成功还是失败, 返回的status都是200, 找到key了, API返回的就是key; 没找到key, API返回的key里面实际上填写的是错误信息.
image

我的修改:
状态码要表示这个API操作是否成功. 如果成功, 状态码是200, key里面有找到的key; 如果失败, 状态码是错误码, error里面有错误信息.
image

其实, 我这里也许也有不合规范的地方. 如果是删除, request.method 就不应该是 "POST", 而应该是"DELETE" 是吧?

@xyTom
Copy link
Owner

xyTom commented Aug 14, 2023

你好! 其它的功能性的东西, 合不合并看个人对项目的定义和取舍. 但是有一个地方, 关于API的接口的定义和使用方法, 想和你探讨一下.

你的代码, 不管成功还是失败, 返回的status都是200, 找到key了, API返回的就是key; 没找到key, API返回的key里面实际上填写的是错误信息. image

我的修改: 状态码要表示这个API操作是否成功. 如果成功, 状态码是200, key里面有找到的key; 如果失败, 状态码是错误码, error里面有错误信息. image

其实, 我这里也许也有不合规范的地方. 如果是删除, request.method 就不应该是 "POST", 而应该是"DELETE" 是吧?

是的,你提出的API接口定义确实要规范一些,按常理来说如果失败状态代码返回500确实更加合理一些,我之前这么做主要想的是为了简单一些,这样的话前端代码就不需要判断后端返回的内容是否错误,只需要把后端返回JSON当中的key对应的值赋值到页面弹出的modal框中即可。

即如果正确生成了,则弹出的model框会显示对应的短链接,如果生成错误,则显示对应的错误信息,相当于这样设计的话,就复用了同样的一段代码去应对两种情况。简而言之,就是我偷了点懒,当然这样弄就不太规范了。

个人感觉你的方式会更加的合理和规范,也更符合直觉便于理解,如果需要你可以再提交一个pull request,将关于API接口的规范化修改提交到main分支中

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.

8 participants