Giter Club home page Giter Club logo

short-url's Introduction

short-url

能够使用自己的域名,简化 url

示例网站:https://s.hal.wang

例如

  1. 知乎任意一个详情页
  2. 一键部署地址
    • 短地址: https://s.hal.wang/sud
    • 原地址: https://console.cloud.tencent.com/tcb/env/index?action=CreateAndDeployCloudBaseProject&appUrl=https%3A%2F%2Fgithub.com%2Fhal-wang%2Fshort-url&branch=main

改用自己的域名,你需要做:

  1. 一键部署

  2. 配置 HTTP 访问服务

  • 添加自定义域名,如 s.hal.wang

解决 CloudBase Framework Node.JS 版本过低问题

截至目前, CloudBase Framework 最高仅支持 Node.JS 12.16,很多依赖已经无法正常使用了

这将导致部署的云函数启动失败

为了解决这个问题,你需要或先创建同名云函数再部署,创建云函数时选择 nodejs 版本为 16.13 (目前最高的支持)

或一键部署后删除 todo 云函数,然后再重建一个同名函数,然后再次部署。

注意事项

  1. API 生成短链接中的域名,是根据调用 API 时头部的 short-url-origin。因此调用 API 需要注意头部参数。
  2. 跳转使用 302,因为可能存在限制访问次数的短链接。如果使用 301 则无法正确统计。
  3. 随机部分,默认是 4 位,如果 4 位的冲突较多,则生成 5 位。以此类推,长度不限。

二次开发

如果现有功能不能满足,你可以进行二次开发

API

short-url-api 下创建文件 .env.local,内容如下

SCF_NAMESPACE=cloudbase环境id
SECRET_KEY=腾讯云 secret key
SECRET_ID=腾讯云 secret id

运行 API

先安装依赖,在 short-url-api 下执行

yarn install

再使用 vscode 打开 short-url-api,直接 F5 开始调试

或在 short-url-api 目录下执行

yarn start

Web

先安装依赖,在 short-url-web 下执行

yarn install

再执行下面命令运行

yarn start

或使用已发布的接口,需要修改 short-url-web/.env.development 文件中的 VITE_GLOB_PROXY_API_URL

然后运行

yarn start:stage

发布

可以本地使用 @cloudbase/cli 发布,也可以使用 GitHub Actions 持续集成

cli 发布

在项目根目录下创建 .env.local (注意是项目根目录,不是 API 或 Web 下)

内容如下

ENV_ID=cloudbase环境id

在项目根目录下运行以下命令发布

npm run deploy

GitHub Actions

仓库增加 Secrets,在 Settings -> Secrets -> Actions,点击 New repository secret 按钮

  • TENCENT_SECRET_ID: 腾讯云 secret id
  • TENCENT_SECRET_KEY: 腾讯云 secret key
  • ENV: 与 cli 发布.env.local 文件内容相同

配置完成后,每次 main 分支提交代码就会自动发布到 CloudBase

发布进度可在仓库 Actions 中看到

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.