Skip to content

Commit

Permalink
Allow setting a custom path for the UI (#23)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
weinshel authored Apr 3, 2024
1 parent 0390a8d commit 61df52e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ <h2>Shorten a URL ✨</h2>
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 {
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 61df52e

Please sign in to comment.