Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Vercel and GitHub Private Repo (#62 #39) #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ coverage

# dependencies
node_modules

# vercel
.vercel
File renamed without changes.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ The result will be faster and more lightweight than any other solution out there
- Refreshes the cache every **15 minutes** (custom interval [possible](#options))
- When asked for an update, it returns the link to the GitHub asset directly (saves bandwidth)
- Supports **macOS** and **Windows** apps
- Scales very nicely across multiple [Now](https://zeit.co/now) instances
- Scales very nicely across multiple [Vercel](https://vercel.com) instances

## Usage

With [Now CLI](https://zeit.co/download), you can easily deploy an update server. As the first step, clone the repository:
With [Vercel CLI](https://vercel.com/download), you can easily deploy an update server. As the first step, clone the repository:

```bash
git clone https://github.com/zeit/hazel
git clone https://github.com/vercel/hazel
```

Next, move into the directory:
Expand All @@ -32,7 +32,7 @@ cd hazel
Inside the directory, create a new deployment:

```bash
now -e ACCOUNT="<github-account>" -e REPOSITORY="<github-repository>"
vercel -e ACCOUNT="<github-account>" -e REPOSITORY="<github-repository>"
```

On the command above, you can define the following environment variables:
Expand Down Expand Up @@ -63,7 +63,7 @@ The following environment variables can be used optionally:
- `INTERVAL`: Refreshes the cache every x minutes ([restrictions](https://developer.github.com/changes/2012-10-14-rate-limit-changes/))
- `PRE`: When defined with a value of `1`, only pre-releases will be cached
- `TOKEN`: Your GitHub token (for private repos)
- `URL`: The server's URL (for private repos - when running on [Now](https://zeit.co/now), this field is filled with the URL of the deployment automatically)
- `URL`: The server's URL (for private repos - when running on [Vercel](https://vercel.com), this field is filled with the URL of the deployment automatically)

## Statistics

Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = config => {
router.get('/download', routes.download)
router.get('/download/:platform', routes.downloadPlatform)
router.get('/update/:platform/:version', routes.update)
router.get('/update/:platform/:version/:targetFile', routes.update)
router.get('/update/win32/:version/RELEASES', routes.releases)

return (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = fileName => {

if (
(fileName.includes('mac') || fileName.includes('darwin')) &&
extension === 'zip'
(extension === 'yml')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@backroot curious what this change is for?

) {
return 'darwin'
}

const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage']
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage', 'zip']
return directCache.find(ext => ext === extension) || false
}
20 changes: 18 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Native
const urlHelpers = require('url');
const urlHelpers = require('url')

// Packages
const { send } = require('micro')
Expand Down Expand Up @@ -81,6 +81,10 @@ module.exports = ({ cache, config }) => {
platform = 'dmg'
}

if (platform === 'darwin') {
platform = 'dmg'
}

// Get the latest version from the cache
const latest = await loadCache()

Expand Down Expand Up @@ -110,7 +114,7 @@ module.exports = ({ cache, config }) => {
}

exports.update = async (req, res) => {
const { platform: platformName, version } = req.params
const { platform: platformName, version, targetFile } = req.params

if (!valid(version)) {
send(res, 500, {
Expand Down Expand Up @@ -142,6 +146,18 @@ module.exports = ({ cache, config }) => {
return
}

if (targetFile) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this change for?

if (shouldProxyPrivateDownload) {
for (const platform in latest.platforms) {
if (latest.platforms[platform].name === targetFile) {
proxyPrivateDownload(latest.platforms[platform], req, res)
break
}
}
return
}
}

// Previously, we were checking if the latest version is
// greater than the one on the client. However, we
// only need to compare if they're different (even if
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hazel = require('./index')
const hazel = require('.')

const {
INTERVAL: interval,
Expand Down
16 changes: 0 additions & 16 deletions now.json

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@
},
"lint-staged": {
"*.js": [
"yarn test && :",
"yarn test --passWithNoTests && :",
"prettier --single-quote --no-semi --write --no-editorconfig",
"git add"
]
},
"dependencies": {
"@vercel/node": "^1.8.2",
"async-retry": "1.2.3",
"date-fns": "1.29.0",
"express-useragent": "1.0.12",
"fetch": "1.1.0",
"finalhandler": "1.1.0",
"handlebars": "4.0.11",
"install": "^0.13.0",
"jest": "24.0.0",
"micro": "9.3.3",
"ms": "2.1.1",
"node-fetch": "2.0.0",
"router": "1.3.2",
"semver": "5.5.0",
"stream-to-string": "1.1.0",
"test-listen": "1.1.0"
"test-listen": "1.1.0",
"vercel": "^20.1.0",
"yarn": "^1.22.10"
},
"devDependencies": {
"eslint-config-prettier": "2.9.0",
Expand Down
21 changes: 21 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 2,
"env": {
"ACCOUNT": "Your GitHub Account",
"REPOSITORY": "Yout GitHub Repository",
"TOKEN": "Your GitHub Token",
"URL": "http://localhost:3000"
},
"builds": [
{
"src": "lib/*.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": ".*",
"dest": "lib/server.js"
}
]
}