Use git URL from tunnel if available

This commit is contained in:
Chris Wanstrath 2026-03-08 23:26:12 -07:00
parent e0347444aa
commit d9533032bc
3 changed files with 19 additions and 6 deletions

View File

@ -641,8 +641,13 @@ app.on('GET', ['/:repo{.+\\.git}/info/refs', '/:repo/info/refs'], async c => {
return c.text('Invalid service', 400) return c.text('Invalid service', 400)
} }
if (service === 'git-receive-pack' && c.req.header('x-sneaker')) { if (c.req.header('x-sneaker')) {
return c.text('Push access denied over sneaker', 403) if (service === 'git-receive-pack') {
return c.text('Push access denied over sneaker', 403)
}
if (await getVisibility(repoParam) !== 'public') {
return c.text('Repository not found', 404)
}
} }
if (service === 'git-receive-pack') { if (service === 'git-receive-pack') {
@ -666,6 +671,10 @@ app.on('POST', ['/:repo{.+\\.git}/git-upload-pack', '/:repo/git-upload-pack'], a
return c.text('Invalid repository name', 400) return c.text('Invalid repository name', 400)
} }
if (c.req.header('x-sneaker') && await getVisibility(repoParam) !== 'public') {
return c.text('Repository not found', 404)
}
const bare = repoPath(repoParam) const bare = repoPath(repoParam)
if (!(await dirExists(bare))) { if (!(await dirExists(bare))) {
return c.text('Repository not found', 404) return c.text('Repository not found', 404)

View File

@ -179,7 +179,7 @@ export async function newApp(name: string | undefined, options: NewAppOptions) {
await run(['git', 'init']) await run(['git', 'init'])
await run(['git', 'add', '.']) await run(['git', 'add', '.'])
await run(['git', 'commit', '-m', 'init']) await run(['git', 'commit', '-m', 'init'])
await run(['git', 'remote', 'add', 'toes', gitUrl(appName)]) await run(['git', 'remote', 'add', 'toes', await gitUrl(appName)])
await run(['git', 'push', 'toes', 'main']) await run(['git', 'push', 'toes', 'main'])
console.log(color.green(`✓ Created ${appName}`)) console.log(color.green(`✓ Created ${appName}`))
@ -196,7 +196,7 @@ export async function getApp(name: string, directory?: string) {
return return
} }
const url = gitUrl(name) const url = await gitUrl(name)
const args = ['git', 'clone', url] const args = ['git', 'clone', url]
if (directory) args.push(directory) if (directory) args.push(directory)
const proc = Bun.spawn(args, { stdout: 'inherit', stderr: 'inherit' }) const proc = Bun.spawn(args, { stdout: 'inherit', stderr: 'inherit' })

View File

@ -1,4 +1,4 @@
import type { Manifest } from '@types' import type { App, Manifest } from '@types'
import { buildAppUrl } from '@urls' import { buildAppUrl } from '@urls'
import { AsyncLocalStorage } from 'node:async_hooks' import { AsyncLocalStorage } from 'node:async_hooks'
@ -21,7 +21,11 @@ export const HOST = process.env.TOES_URL
? normalizeUrl(process.env.TOES_URL) ? normalizeUrl(process.env.TOES_URL)
: DEFAULT_HOST : DEFAULT_HOST
export const gitUrl = (name: string) => `${buildAppUrl('git', HOST)}/${name}` export async function gitUrl(name: string): Promise<string> {
const git: App | undefined = await get('/api/apps/git')
if (git?.tunnelUrl) return `${git.tunnelUrl}/${name}`
return `${buildAppUrl('git', HOST)}/${name}`
}
export const getSignal = () => signalStore.getStore() export const getSignal = () => signalStore.getStore()