https://github.com/dofy/short-url
Short URL Service
https://github.com/dofy/short-url
Last synced: 11 months ago
JSON representation
Short URL Service
- Host: GitHub
- URL: https://github.com/dofy/short-url
- Owner: dofy
- Created: 2015-01-02T07:31:48.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T10:21:51.000Z (about 3 years ago)
- Last Synced: 2025-01-14T10:26:52.363Z (12 months ago)
- Language: JavaScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Short URL Service
### 安装
* `clone` 项目到本地
* 执行 `npm install`
* 进入 `lib` 目录
* `cp config.sample.js config.js`
* 编辑 `config.js` 文件,可以设置 `MongoDB` 链接,并修改要在短链接 `key` 中出现的字符(不能有重复字符)
* 设置 X 位字符,就会生成 X 进制的数字
* 比如刚好设置 10 位字符 `abcdefghij`
* 数字 0 对应 a,数字 9 对应 j,数字 13,对应 bd
* 数字 <=> 字符 算法参考 `lib/smartNumber.js`
* 默认设置了数字+大小写字母共 62 个字符(若不想生成的 key 是连续规律的,采用字符乱序是个不错的选择)
* 62 个字符当全部采用 5 位字符作为 key,可以保存 9亿+ 个记录
* 调试运行 `node short.js`
* 后台运行 `npm start`
### create your short url
```
http://your.domain/_?url=xxx
```
**result**
```json
{"url": "http://your.service.domain/{{key}}"}
```
### visit your short url
```
http://your.service.domain/{{key}}
```