basic auth
This commit is contained in:
parent
5948263c6d
commit
c7fa05f224
14
README.md
14
README.md
|
|
@ -1,3 +1,15 @@
|
|||
# 👟 sneaker
|
||||
|
||||
don't ask
|
||||
don't ask
|
||||
|
||||
## basic auth
|
||||
|
||||
users:
|
||||
|
||||
- corey
|
||||
- defunkt
|
||||
- spike
|
||||
|
||||
password:
|
||||
|
||||
- 888
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "bun --hot src/server.tsx",
|
||||
"prod": "env NODE_ENV=production bun src/server.tsx",
|
||||
"start": "bun run src/server.tsx"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -17,4 +18,4 @@
|
|||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { Hono } from "hono"
|
||||
import { upgradeWebSocket, websocket } from "hono/bun"
|
||||
import { uniqueNamesGenerator, adjectives, animals, colors } from "unique-names-generator"
|
||||
import { basicAuth } from "hono/basic-auth"
|
||||
import { uniqueNamesGenerator, adjectives, animals } from "unique-names-generator"
|
||||
|
||||
type Request = {
|
||||
id: string
|
||||
|
|
@ -30,6 +31,31 @@ const app = new Hono
|
|||
|
||||
app.get("/health", c => c.text("ok"))
|
||||
|
||||
const users = ["corey", "defunkt", "spike"]
|
||||
const password = "888"
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
app.use(basicAuth({
|
||||
verifyUser: (username, pass) =>
|
||||
users.includes(username) && password === pass
|
||||
}))
|
||||
}
|
||||
|
||||
app.get("/tunnels", c => {
|
||||
return c.html(<ul>
|
||||
{Object.keys(connections).map(key =>
|
||||
<li><a href={`/tunnel/${key}`}>{key}</a> ({connections[key]?.app})</li>
|
||||
)}
|
||||
</ul>)
|
||||
})
|
||||
|
||||
app.get("/tunnel/:app", c => {
|
||||
const url = new URL(c.req.url)
|
||||
const port = url.port === "80" ? "" : `:${url.port}`
|
||||
const hostname = url.hostname
|
||||
return c.redirect(`http://${c.req.param("app")}.${hostname}${port}`)
|
||||
})
|
||||
|
||||
app.get("/tunnel", c => {
|
||||
const app = c.req.query("app")
|
||||
if (!app)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user