Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
/ website Public archive
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .netlify/state.json

This file was deleted.

1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
4 changes: 0 additions & 4 deletions _headers

This file was deleted.

64 changes: 64 additions & 0 deletions functions/[[catchall]].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable require-await */

export type Env = Record<never, never>;

const REDIRECT_URL_BASE = "https://api.zws.im";

const SHORT_CHARS: readonly string[] = [
"\u200c",
"\u200d",
"\udb40\udc61",
"\udb40\udc62",
"\udb40\udc63",
"\udb40\udc64",
"\udb40\udc65",
"\udb40\udc66",
"\udb40\udc67",
"\udb40\udc68",
"\udb40\udc69",
"\udb40\udc6a",
"\udb40\udc6b",
"\udb40\udc6c",
"\udb40\udc6d",
"\udb40\udc6e",
"\udb40\udc6f",
"\udb40\udc70",
"\udb40\udc71",
"\udb40\udc72",
"\udb40\udc73",
"\udb40\udc74",
"\udb40\udc75",
"\udb40\udc76",
"\udb40\udc77",
"\udb40\udc78",
"\udb40\udc79",
"\udb40\udc7a",
"\udb40\udc7f",
"test",
];

const SHORTENED_URL_REGEXP = new RegExp(`/(?:${SHORT_CHARS.join("|")})+$`, "g");

function getRedirect(context: EventContext<Env, string, unknown>): string | Request {
const path = context.functionPath;

if (path.startsWith("/api")) {
const redirectUrl = new URL(REDIRECT_URL_BASE);
redirectUrl.pathname = path.slice("/api".length);

return new Request(redirectUrl, context.request);
}

SHORTENED_URL_REGEXP.lastIndex = 0;

if (context.request.method.toLowerCase() === "get" && SHORTENED_URL_REGEXP.test(path)) {
const redirectUrl = new URL(REDIRECT_URL_BASE);
redirectUrl.pathname = path;

return redirectUrl.toString();
}

return context.request;
}

export const onRequest: PagesFunction<Env> = async (context) => fetch(getRedirect(context));
38 changes: 0 additions & 38 deletions netlify.toml

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"firebase": "8.10.1"
},
"devDependencies": {
"@cloudflare/workers-types": "4.20221111.1",
"@dice-discord/eslint-config": "3.0.0",
"@types/clipboard": "2.0.1",
"@typescript-eslint/eslint-plugin": "5.47.1",
Expand All @@ -22,11 +23,11 @@
"eslint": "8.30.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"netlify-cli": "12.5.0",
"parcel": "1.12.4",
"prettier": "2.8.1",
"sass": "1.57.1",
"typescript": "4.9.4"
"typescript": "4.9.4",
"wrangler": "2.6.2"
},
"keywords": [
"url shortener",
Expand All @@ -42,7 +43,7 @@
},
"scripts": {
"build": "parcel build src/*.html",
"postbuild": "cp src/assets/image/phishing.png src/keybase.txt dist",
"postbuild": "cp src/assets/image/phishing.png src/keybase.txt src/_redirects src/_routes.json dist",
"lint": "eslint .",
"prebuild": "rm -rf dist",
"prettier": "prettier --check .",
Expand Down
4 changes: 1 addition & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# zws.im [![Netlify deploy status](https://api.netlify.com/api/v1/badges/a4195062-7869-4330-b512-fb9385f094f5/deploy-status)](https://app.netlify.com/sites/zerowidthshortener/deploys)

[![Deploys by Netlify](https://www.netlify.com/img/global/badges/netlify-color-bg.svg)](https://www.netlify.com)
# zws.im

This is the website for Zero Width Shortener. It consumes the API for shortening and retrieving URLs.
Learn more about ZWS in [the main repository](https://github.com/zws-im/zws).
1 change: 1 addition & 0 deletions src/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/status https://status.zws.im/ 301
5 changes: 5 additions & 0 deletions src/_routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"include": ["/*"],
"exclude": []
}
1 change: 0 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ <h2 class="subtitle">Shorten URLs using invisible spaces.</h2>
<p>
The API was made with <a href="https://github.com/zws-im/zws">Fastify, Prisma, and TypeScript</a>
</p>
<p><a href="https://netlify.com">This site is powered by Netlify</a></p>
</div>
<div class="column">
<p class="subtitle is-size-4">Links</p>
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// The Firebase module will make TypeScript mad otherwise
"allowSyntheticDefaultImports": true,
// Used for loading version number
"resolveJsonModule": true
"resolveJsonModule": true,

"types": ["@cloudflare/workers-types"]
},
"include": ["src/assets/ts", "src/types", "@sentry/types"]
"include": ["src/assets/ts", "src/types", "@sentry/types", "functions"]
}
4 changes: 4 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "zws"
main = "src/workers/index.ts"
compatibility_date = "2023-01-03"
routes = ["zws.im/*"]
Loading