Skip to content

Commit

Permalink
add 404 message for platform=linux. #45
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed May 15, 2018
1 parent a5f7b58 commit 51a0fbd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ class Updates {
async handle (req, res) {
let segs = req.url.split(/[/?]/).filter(Boolean)
const [account, repository, platform, version, file] = segs

if (!account || !repository || !platform || !version) {
redirect(res, 'https://github.com/electron/update.electronjs.org')
} else if (platform !== 'darwin' && platform !== 'win32') {
const message = `Unsupported platform: "${platform}". Supported: darwin, win32.`
notFound(res, message)
} else if (file === 'RELEASES') {
await this.handleReleases(res, account, repository)
} else {
Expand Down Expand Up @@ -194,9 +198,9 @@ const assetPlatform = fileName => {
return false
}

const notFound = res => {
const notFound = (res, message = 'Not found') => {
res.statusCode = 404
res.end('Not found')
res.end(message)
}

const noContent = res => {
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ test('Updates', async t => {
}
})
})

await t.test('Linux', async t => {
await t.test('not supported', async t => {
const res = await fetch(`${address}/owner/repo/linux/0.0.0`)
t.equal(res.status, 404)
const body = await res.text()
t.equal(
body,
'Unsupported platform: "linux". Supported: darwin, win32.'
)
})
})

await t.test('Others', async t => {
await t.test('not supported', async t => {
const res = await fetch(`${address}/owner/repo/os/0.0.0`)
t.equal(res.status, 404)
const body = await res.text()
t.equal(body, 'Unsupported platform: "os". Supported: darwin, win32.')
})
})
})

server.close()
Expand Down

0 comments on commit 51a0fbd

Please sign in to comment.