https://github.com/ygweric/short-url 欢迎 star 鼓励
Powered by NestJS + React
NestJs + TypeScript + TypeORM + Sqlite
npm i
npm start
will run server in open http://localhost:3000/
npm run test
npm run test:cov
--------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------|---------|----------|---------|---------|-------------------
All files | 96.25 | 78.57 | 100 | 95.52 |
common | 100 | 100 | 100 | 100 |
config.ts | 100 | 100 | 100 | 100 |
errorCode.ts | 100 | 100 | 100 | 100 |
stringUtil.ts | 100 | 100 | 100 | 100 |
controllers | 96 | 83.33 | 100 | 94.74 |
app.controller.ts | 96 | 83.33 | 100 | 94.74 | 16
entities | 100 | 100 | 100 | 100 |
url.ts | 100 | 100 | 100 | 100 |
services | 93.1 | 66.67 | 100 | 91.67 |
app.service.ts | 93.1 | 66.67 | 100 | 91.67 | 14,32
--------------------|---------|----------|---------|---------|-------------------
采用数据库 sum 自增的方式, 将 sum 总数转变为 62 进制的字符串
对于不超过 8 位的短链接,最多可以存放 62^8 ≈ 218,340,105,584,896 个链接
export class Url {
@PrimaryColumn('varchar', { nullable: false })
public shortUrl: string;
@Column("text", { nullable: false})
public longUrl: string;
}
── src
│ ├── app.module.ts
│ ├── common 通用模块
│ │ ├── __tests__
│ │ │ └── stringUtil.spec.ts
│ │ ├── config.ts
│ │ ├── errorCode.ts
│ │ └── stringUtil.ts
│ ├── controllers 路由
│ │ ├── __tests__
│ │ │ └── app.controller.spec.ts
│ │ └── app.controller.ts
│ ├── entities ORM 实例
│ │ └── url.ts
│ ├── index.ts
│ ├── main.ts
│ ├── middlewares
│ ├── migration
│ └── services 服务层,负责 entity 和 controller 的通信
│ ├── __tests__
│ │ └── app.service.spec.ts
│ └── app.service.ts
React + TypeScript + Axios + AntD
npm i
npm start
open http://localhost:8080/
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.