Skip to content

Commit d068710

Browse files
committed
Support for Vercel and GitHub Private Repo (#62 #39)
1 parent e5cf41e commit d068710

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ coverage
33

44
# dependencies
55
node_modules
6+
7+
# vercel
8+
.vercel
File renamed without changes.

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = config => {
3535
router.get('/download', routes.download)
3636
router.get('/download/:platform', routes.downloadPlatform)
3737
router.get('/update/:platform/:version', routes.update)
38+
router.get('/update/:platform/:version/:targetFile', routes.update)
3839
router.get('/update/win32/:version/RELEASES', routes.releases)
3940

4041
return (req, res) => {

lib/platform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module.exports = fileName => {
66

77
if (
88
(fileName.includes('mac') || fileName.includes('darwin')) &&
9-
extension === 'zip'
9+
(extension === 'yml')
1010
) {
1111
return 'darwin'
1212
}
1313

14-
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage']
14+
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage', 'zip']
1515
return directCache.find(ext => ext === extension) || false
1616
}

lib/routes.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Native
22
const urlHelpers = require('url');
3+
const { extname } = require('path');
34

45
// Packages
56
const { send } = require('micro')
@@ -81,6 +82,10 @@ module.exports = ({ cache, config }) => {
8182
platform = 'dmg'
8283
}
8384

85+
if (platform === 'darwin') {
86+
platform = 'dmg'
87+
}
88+
8489
// Get the latest version from the cache
8590
const latest = await loadCache()
8691

@@ -110,7 +115,7 @@ module.exports = ({ cache, config }) => {
110115
}
111116

112117
exports.update = async (req, res) => {
113-
const { platform: platformName, version } = req.params
118+
const { platform: platformName, version, targetFile } = req.params
114119

115120
if (!valid(version)) {
116121
send(res, 500, {
@@ -142,6 +147,18 @@ module.exports = ({ cache, config }) => {
142147
return
143148
}
144149

150+
if (targetFile) {
151+
if (shouldProxyPrivateDownload) {
152+
for (let p in latest.platforms) {
153+
if (latest.platforms[p].name === targetFile) {
154+
proxyPrivateDownload(latest.platforms[p], req, res)
155+
break;
156+
}
157+
}
158+
return
159+
}
160+
}
161+
145162
// Previously, we were checking if the latest version is
146163
// greater than the one on the client. However, we
147164
// only need to compare if they're different (even if

now.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@
2929
]
3030
},
3131
"dependencies": {
32+
"@vercel/node": "^1.8.2",
3233
"async-retry": "1.2.3",
3334
"date-fns": "1.29.0",
3435
"express-useragent": "1.0.12",
3536
"fetch": "1.1.0",
3637
"finalhandler": "1.1.0",
3738
"handlebars": "4.0.11",
39+
"install": "^0.13.0",
3840
"jest": "24.0.0",
3941
"micro": "9.3.3",
4042
"ms": "2.1.1",
4143
"node-fetch": "2.0.0",
4244
"router": "1.3.2",
4345
"semver": "5.5.0",
4446
"stream-to-string": "1.1.0",
45-
"test-listen": "1.1.0"
47+
"test-listen": "1.1.0",
48+
"vercel": "^20.1.0"
4649
},
4750
"devDependencies": {
4851
"eslint-config-prettier": "2.9.0",

vercel.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": 2,
3+
"env": {
4+
"ACCOUNT": "Your GitHub Account",
5+
"REPOSITORY": "Your GirHub Repository",
6+
"TOKEN": "Your GitHub Token",
7+
"URL": "http://localhost:3000"
8+
},
9+
"builds": [
10+
{
11+
"src": "lib/*.js",
12+
"use": "@vercel/node"
13+
}
14+
],
15+
"routes": [
16+
{
17+
"src": ".*",
18+
"dest": "lib/server.js"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)