Support bare and non-.git URL patterns

This commit is contained in:
Chris Wanstrath 2026-03-01 09:01:47 -08:00
parent 7ee9163f76
commit 4b920a247d

View File

@ -11,7 +11,7 @@ const DATA_DIR = process.env.DATA_DIR!
const TOES_URL = process.env.TOES_URL! const TOES_URL = process.env.TOES_URL!
const MAX_VERSIONS = 5 const MAX_VERSIONS = 5
const REPOS_DIR = join(DATA_DIR, 'repos') const REPOS_DIR = resolve(DATA_DIR, 'repos')
const VALID_NAME = /^[a-zA-Z0-9_-]+$/ const VALID_NAME = /^[a-zA-Z0-9_-]+$/
const app = new Hype({ prettyHTML: false, layout: false }) const app = new Hype({ prettyHTML: false, layout: false })
@ -412,8 +412,8 @@ app.get('/styles.css', c =>
c.text(baseStyles + stylesToCSS(), 200, { 'Content-Type': 'text/css; charset=utf-8' }), c.text(baseStyles + stylesToCSS(), 200, { 'Content-Type': 'text/css; charset=utf-8' }),
) )
// GET /:repo.git/info/refs?service=git-upload-pack|git-receive-pack // GET /:repo[.git]/info/refs?service=git-upload-pack|git-receive-pack
app.get('/:repo{.+\\.git}/info/refs', async c => { app.on('GET', ['/:repo{.+\\.git}/info/refs', '/:repo/info/refs'], async c => {
const repoParam = c.req.param('repo').replace(/\.git$/, '') const repoParam = c.req.param('repo').replace(/\.git$/, '')
const service = c.req.query('service') const service = c.req.query('service')
@ -438,8 +438,8 @@ app.get('/:repo{.+\\.git}/info/refs', async c => {
return res ?? c.text('Repository not found', 404) return res ?? c.text('Repository not found', 404)
}) })
// POST /:repo.git/git-upload-pack // POST /:repo[.git]/git-upload-pack
app.post('/:repo{.+\\.git}/git-upload-pack', async c => { app.on('POST', ['/:repo{.+\\.git}/git-upload-pack', '/:repo/git-upload-pack'], async c => {
const repoParam = c.req.param('repo').replace(/\.git$/, '') const repoParam = c.req.param('repo').replace(/\.git$/, '')
if (!validRepoName(repoParam)) { if (!validRepoName(repoParam)) {
@ -454,8 +454,8 @@ app.post('/:repo{.+\\.git}/git-upload-pack', async c => {
return gitRpc(repoParam, 'git-upload-pack', c.req.raw.body) return gitRpc(repoParam, 'git-upload-pack', c.req.raw.body)
}) })
// POST /:repo.git/git-receive-pack // POST /:repo[.git]/git-receive-pack
app.post('/:repo{.+\\.git}/git-receive-pack', async c => { app.on('POST', ['/:repo{.+\\.git}/git-receive-pack', '/:repo/git-receive-pack'], async c => {
const repoParam = c.req.param('repo').replace(/\.git$/, '') const repoParam = c.req.param('repo').replace(/\.git$/, '')
if (!validRepoName(repoParam)) { if (!validRepoName(repoParam)) {