From 61df52e4f0b0721fd642104ac50db5575c6be89e Mon Sep 17 00:00:00 2001 From: Ben Weinshel <6042920+weinshel@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:41:55 -0400 Subject: [PATCH] Allow setting a custom path for the UI (#23) * Allow setting a custom path for the UI Allow defining an admin path in src/index.ts, which allows the base domain to be used as a redirect source. * lint * fix form when key is empty --- src/form.html | 3 ++- src/index.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/form.html b/src/form.html index 54332ec..7360c6b 100644 --- a/src/form.html +++ b/src/form.html @@ -183,7 +183,8 @@

Shorten a URL ✨

const value = document.getElementById('value').value const password = document.getElementById('password').value - const url = key === '' ? window.location.href : window.location.href + key + const baseUrlPath = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '/' + const url = key === '' ? window.location.href : baseUrlPath + key const method = key === '' ? 'POST' : 'PUT' try { diff --git a/src/index.ts b/src/index.ts index adfcabc..c297a6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,8 @@ import * as st from 'simple-runtypes' // html.d.ts tells typescript that this is a normal thing to do import creationPageHtml from './form.html' +const ADMIN_PATH = '/' + type Variables = { path: string key: string @@ -87,7 +89,7 @@ app.use('*', async (c, next) => { }) // retrieve list of keys -app.get('/', async (c) => { +app.get(ADMIN_PATH, async (c) => { if (c.req.header('Authorization')) { if (!checkAuth(c)) { return unauthorized(c) @@ -171,7 +173,7 @@ app.delete('*', async (c) => { app.put('*', createLink) // add random key -app.post('/', async (c) => { +app.post(ADMIN_PATH, async (c) => { const rawBody = await c.req.text() if (!rawBody) {