Skip to content

Commit 325281e

Browse files
authored
Merge pull request #46 from electron/add/404-message-linux
add 404 message for platform=linux. #45
2 parents a5f7b58 + 51a0fbd commit 325281e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ class Updates {
5353
async handle (req, res) {
5454
let segs = req.url.split(/[/?]/).filter(Boolean)
5555
const [account, repository, platform, version, file] = segs
56+
5657
if (!account || !repository || !platform || !version) {
5758
redirect(res, 'https://github.com/electron/update.electronjs.org')
59+
} else if (platform !== 'darwin' && platform !== 'win32') {
60+
const message = `Unsupported platform: "${platform}". Supported: darwin, win32.`
61+
notFound(res, message)
5862
} else if (file === 'RELEASES') {
5963
await this.handleReleases(res, account, repository)
6064
} else {
@@ -194,9 +198,9 @@ const assetPlatform = fileName => {
194198
return false
195199
}
196200

197-
const notFound = res => {
201+
const notFound = (res, message = 'Not found') => {
198202
res.statusCode = 404
199-
res.end('Not found')
203+
res.end(message)
200204
}
201205

202206
const noContent = res => {

test/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,27 @@ test('Updates', async t => {
255255
}
256256
})
257257
})
258+
259+
await t.test('Linux', async t => {
260+
await t.test('not supported', async t => {
261+
const res = await fetch(`${address}/owner/repo/linux/0.0.0`)
262+
t.equal(res.status, 404)
263+
const body = await res.text()
264+
t.equal(
265+
body,
266+
'Unsupported platform: "linux". Supported: darwin, win32.'
267+
)
268+
})
269+
})
270+
271+
await t.test('Others', async t => {
272+
await t.test('not supported', async t => {
273+
const res = await fetch(`${address}/owner/repo/os/0.0.0`)
274+
t.equal(res.status, 404)
275+
const body = await res.text()
276+
t.equal(body, 'Unsupported platform: "os". Supported: darwin, win32.')
277+
})
278+
})
258279
})
259280

260281
server.close()

0 commit comments

Comments
 (0)