Skip to content

Commit

Permalink
add optional /update/ path prefix. closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Apr 6, 2018
1 parent 7a39418 commit 484b7f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ WIP public electron update server.

## Routes

### `/:owner/:repo/:platform/:version`
### `/:owner/:repo/win32/:version/RELEASES`
### `/update?/:owner/:repo/:platform/:version`
### `/update?/:owner/:repo/win32/:version/RELEASES`

## Development

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Updates {

async handle (req, res) {
this.log(req.method, req.url, '...')
const segs = req.url.split(/[/?]/).filter(Boolean)
let segs = req.url.split(/[/?]/).filter(Boolean)
if (segs[0] === 'update') segs = segs.slice(1)
const [account, repository, platform, version, file] = segs
if (!account || !repository || !platform || !version) {
notFound(res)
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ test('Updates', async t => {
}
})

await t.test('optional /update/ path prefix', async t => {
for (let i = 0; i < cache; i++) {
const res = await fetch(
`${address}/update/dat-land/dat-desktop/darwin/1.0.0`
)
t.equal(res.status, 200)
const body = await res.json()
t.ok(body.name)
t.match(body.url, /-mac\.zip$/)
t.ok(body.notes)
}
})

await t.test('exists but no updates', async t => {
let res = await fetch(
`https://api.github.com/repos/dat-land/dat-desktop/releases?per_page=100`,
Expand Down

0 comments on commit 484b7f0

Please sign in to comment.