Giter Club home page Giter Club logo

hazel's Introduction

Hazel

CircleCI XO code style

This project lets you deploy an update server for Electron apps with ease: You only need to click a button.

The result will be faster and more lightweight than any other solution out there! ๐Ÿš€

  • Recommended by Electron here
  • Built on top of micro, the tiniest HTTP framework for Node.js
  • Pulls the latest release data from GitHub Releases and caches it in memory
  • Refreshes the cache every 15 minutes (custom interval possible)
  • When asked for an update, it returns the link to the GitHub asset directly (saves bandwidth)
  • Supports macOS and Windows apps
  • Scales infinitely on Vercel Serverless Functions

Usage

Open this link in a new tab to deploy Hazel on Vercel:

Deploy with Vercel

Once it's deployed, paste the deployment address into your code (please keep in mind that updates should only occur in the production version of the app, not while developing):

const { app, autoUpdater } = require('electron')

const server = <your-deployment-url>
const url = `${server}/update/${process.platform}/${app.getVersion()}`

autoUpdater.setFeedURL({ url })

That's it! โœ…

From now on, the auto updater will ask your Hazel deployment for updates!

Options

The following environment variables can be used optionally:

  • INTERVAL: Refreshes the cache every x minutes (restrictions) (defaults to 15 minutes)
  • 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 Vercel, this field is filled with the URL of the deployment automatically)

Statistics

Since Hazel routes all the traffic for downloading the actual application files to GitHub Releases, you can use their API to determine the download count for a certain release.

As an example, check out the latest Hyper release and search for mac.zip. You'll find a release containing a sub property named download_count with the amount of downloads as its value.

Routes

/

Displays an overview page showing the cached repository with the different available platforms and file sizes. Links to the repo, releases, specific cached version and direct downloads for each platform are present.

/download

Automatically detects the platform/OS of the visitor by parsing the user agent and then downloads the appropriate copy of your application.

If the latest version of the application wasn't yet pulled from GitHub Releases, it will return a message and the status code 404. The same happens if the latest release doesn't contain a file for the detected platform.

/download/:platform

Accepts a platform (like "darwin" or "win32") to download the appropriate copy your app for. I generally suggest using either process.platform (more) or os.platform() (more) to retrieve this string.

If the cache isn't filled yet or doesn't contain a download link for the specified platform, it will respond like /.

/update/:platform/:version

Checks if there is an update available by reading from the cache.

If the latest version of the application wasn't yet pulled from GitHub Releases, it will return the 204 status code. The same happens if the latest release doesn't contain a file for the specified platform.

/update/win32/:version/RELEASES

This endpoint was specifically crafted for the Windows platform (called "win32" in Node.js).

Since the Windows version of Squirrel (the software that powers auto updates inside Electron) requires access to a file named "RELEASES" when checking for updates, this endpoint will respond with a cached version of the file that contains a download link to a .nupkg file (the application update).

Programmatic Usage

You can add Hazel to an existing HTTP server, if you want. For example, this will allow you to implement custom analytics on certain paths.

const hazel = require('hazel-server')

http.createServer((req, res) => {
  hazel(req, res)
})

Contributing

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Move into the directory of your clone: cd hazel
  3. Install Vercel CLI and run the development server: vercel dev

Credits

Huge thanks to my (@leo's) friend Andy, who suggested the name "Hazel" (since the auto updater software inside Electron is called "Squirrel") and Matheus for collecting ideas with me.

Author

Leo Lamprecht (@notquiteleo) - Vercel

hazel's People

Contributors

andybitz avatar bhageena avatar dominiklessel avatar ilkaydnc avatar itsnwa avatar karanjthakkar avatar labhanshagrawal avatar leo avatar nathanvogel avatar robbiethewagner avatar safinn avatar styks1987 avatar thealexbaron avatar timneutkens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hazel's Issues

Doesn't work for Github private repo

The routes of hazel doesn't seem to work with private repo

DOESN'T WORK

const server = "https://clovis-desktop-hazel-upd.aarbel.now.sh"
const updaterFeedURL = `${server}/update/${process.platform}/${app.getVersion()}`
โ€ฆ
autoUpdater.setFeedURL(updaterFeedURL);

Error:
Unhandled rejection Error: Cannot find channel "latest-mac.yml" update info: HttpError: 404

Please double check that your authentication token is correct. Due to security reasons actual status maybe not reported, but 404.\n

WORKS

const updaterFeedURL = {
    provider: 'github',
    owner: 'my-team',
    repo: 'my-repo',
    token: 'my-github-token',
}

autoUpdater.setFeedURL(updaterFeedURL);

How to use hazel with github Team's private repository ?

I've got this error in the Now project's logs:

(node:1) UnhandledPromiseRejectionWarning: Error: GitHub API responded with 404 for url https://api.github.com/repos/MY_TEAM/MY_ELECTRON_REPO/releases?per_page=100

Hazel doesn't find (or doesn't have access to) the private team's repository. Do you know a way to make it work ? Thanks a lot !

missing_configuration_properties error

I am trying to run a hazel server on Now to autoupdate an Electron app, and I am getting a missing_configuration_properties of Neither ACCOUNT, nor REPOSITORY are defined, which makes no sense because that is exactly what I am specifying in my CLI command

now -e ACCOUNT="dbklabs" -e REPOSITORY="macflix" -e TOKEN="<my token>" -e URL=NOW_URL

On Friday, this was working just fine fyi...
Screen Shot 2019-03-18 at 2 14 51 PM

Private repos?

Does hazel on work on public repos? Supporting private repos would required a GitHub token, which apparently is not currently required or used by hazel.

Windows 10 not detected properly

UserAgent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3218.0 Safari/537.36

gives No download available for your platform!

Fails after missing token

What's up with the token requirement? It's not clear at all... and it exits out of the deployment if you don't provide one.

Support for 32/64 bits achitecture

It would be great to have 32/x64 platform distinction.
For exemple:
deb32, AppImage32,rpm32 and keep current platform without any suffix for 64 bits?

As of now, when a release have 2 different packages for the same platform (32 bits and 64 bits), Hazel redirect to last indexed package.

Support for Linux

Linux support would be awesome to have, since updating electron apps in Linux is not fun, especially if you have to work in a low connectivity area.

Support for GitLab, Gitea?

Hello,

Do you have support for other Git vendors like GitLab & Gitea?

If no, do you have any plans?

If yes, Can I see some examples on using it.

Thanks.

Hazel server stay alive after being closed

Hello, every time i close the hazel server it remains alive in the background even if it prompt "gracefully exiting", how can i achieve a complete shutdown of the app ?

Screenshot 2019-07-11 at 08 46 38

Screenshot 2019-07-11 at 08 51 27

Doc request: methodology with github releases

@leo Thanks again hazel teams for your work !

I saw that now-desktop releases are managed like that:
image

My electron-builder output looks like that:
image

Could you tell us more about the necessity of each file in the release and put that in hazel doc ?

latest-mac.yml // Why this file ?
Now-4.0.19-mac.zip // Why a zip and not only .dmg ?
Now-4.0.19.dmg // What is downloaded on each update ? The dmg of Source code.zip ? 
Now-4.0.19.dmg.blockmap // Electron-builder doesn't generate this file for me, what's its role ? 
now-desktop-4.0.19-full.nupkg // What's this file for ? Electron-builder doesn't seem to generate it in my dist folder
now-desktop-Setup-4.0.19.exe // Ok looks like Windows installer, but same question: on each update is that all the .exe downloaded or only the Source Code.zip ?
RELEASES // That's this file is for ? 
Source code.zip // Ok the source code
Source code.tar.gz // Ok differently compressed source code

Thanks a lot for your help ! ๐Ÿ‘

Version 1.3.0 and above are broken

I deployed the latest version using:

now -e NODE_ENV="production" -e ACCOUNT="wulkano" -e REPOSITORY="kap" -e PORT="80" -e PRE="1" zeit/hazel

And to my surprise the result of going to https://kap-beta-updates.now.sh/update/macos/2.0.0-beta.0 was:

{"name":"v2.0.0-beta.1","notes":"Test","pub_date":"2017-10-31T14:41:53Z","url":"https://api.github.com/repos/wulkano/kap/releases/assets/5210625"}

Notice how the url links to the GitHub asset response and not the binary itself.

With 1.2.2 it works correctly:

{"name":"v2.0.0-beta.1","notes":"Test","pub_date":"2017-10-31T14:41:53Z","url":"https://github.com/wulkano/kap/releases/download/v2.0.0-beta.1/Kap.Beta-2.0.0-beta.1-mac.zip"}

So 1.2.2 works correctly, but 1.3.0 does not, so something must have broken between those versions.

Downloading the update keeps timing out.

I'm using Vercel Hazel for updates and it keeps timing out.

update_failed

Since I am using Vercel, I can't find the exact line of why this is happening to debug this?

Anyone else having this issue?

Thanks.

Private repo not working

Not sure if the documenation is not accurate enough or i am doing something wrong, but i cannot get the setup to run properly.
This is my command:
now -e TOKEN=@github-token -e ACCOUNT="MyAccount" -e REPOSITORY="MyRespository" -e PORT="80" zeit/hazel

This is the message i get immediatly and i need to supply the password for my ssh file:

Didn't find directory. Searching on GitHub...

And this is the error i am getting after ~30 seconds:

Error! Unexpected error. Please try again later. (An unexpected internal error occurred)

What am i doing wrong?

What is the url of latest .dmg or .exe ?

image

I want to put a direct download of the lasted version of my electron app on my website (both for mac and windows).

What should be the right url to the hazel update server to directly download .dmg and .exe but not .zip ?

Thanks for your help !

`ACCOUNT` is an ambiguous env var name

I didn't RTFM for hazel and just jumped in with now -e NODE_ENV="production" zeit/hazel. I was stopped in my tracks when ask to enter a value for ACCOUNT. Referring to the README I can see that this refers to "Your username or organisation name on GitHub", but if the var had a more descriptive name, I wouldn't have had to look. I would suggest something like GITHUB_USERNAME_OR_ORG.

Problem Downloading Releases from Private Github Repos

START RequestId: 2c5ddea1-eb27-41dc-9b0a-05688d6d0bfe Version: $LATEST
2019-12-11T14:14:26.514Z 2c5ddea1-eb27-41dc-9b0a-05688d6d0bfe Unhandled rejection: Error: GitHub API responded with 401 for url https://api.github.com/repos/Vinipux322/urp-eup-converter/releases?per_page=100
at retry (/var/task/lib/cache.js:89:17)
at
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
END RequestId: 2c5ddea1-eb27-41dc-9b0a-05688d6d0bfe
REPORT RequestId: 2c5ddea1-eb27-41dc-9b0a-05688d6d0bfe Duration: 7849.23 ms Billed Duration: 7900 ms Memory Size: 1024 MB Max Memory Used: 30 MB
RequestId: 2c5ddea1-eb27-41dc-9b0a-05688d6d0bfe Process exited before completing request

Can't access update/win32/:version/RELEASES

Updating on MacOS works fine, but on Windows I get the error "Remote release File is empty or corrupted." I'm pretty sure that the error is because of not being able to access /update/win32/:version/RELEASES. When I do this the page just doesn't load and redirect to the previous url I was at.

Is it caching assets ?

Hello,

For public repositories, is Hazel caching the releases list :
for exemple this reponse https://api.github.com/repos/electron/electron/releases

Or does it cache the assets:
for example : https://github.com/electron/electron/releases/download/v8.2.5/chromedriver-v8.2.5-darwin-x64.zip

Thanks

Unhandled rejection: TypeError: Cannot convert undefined or null to object

After deploying hazel, I get the following error:

2019-10-30T12:02:44.603Z 3adf55a3-0bba-4708-98c7-054a6a66ea2e Unhandled rejection: TypeError: Cannot convert undefined or null to object
at Function.keys ()
at exports.overview (/var/task/lib/routes.js:185:12)
at
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
Duration: 263.02 ms Billed Duration: 300 ms Memory Size: 3008 MB Max Memory Used: 32 MB
RequestId: 3adf55a3-0bba-4708-98c7-054a6a66ea2e Process exited before completing request

My project is on a private repository on github. I am using the following command:

now -e ACCOUNT="ACCOUNT_NAME" -e REPOSITORY="REPO_NAME" -e TOKEN="GITHUB_TOKEN" -e URL="https://api.github.com/repos/ACCOUNT_NAME/REPO_NAME/releases?access_token=GITHUB_TOKEN"

Download counts

Just a simple question :
Do Electron download the release from Github or from the release server ?
Don't want to mess up my downloads counts.

When hazel works with express.js

I want to use hazel with express.js. But when I use it with express.js I do not know how to pass the necessary variables (eg repository or username). Can you tell me what to do?

Usage docs to include include dev environment check

Currently the usage docs gives you the code needed to add the auto-updater to an app.
But in dev environment, it of course causes an error.
As such, why not have either a disclaimer or update the docs to include something like:

if (process.env.ELECTRON_DEV) {
  autoUpdater.setFeedURL(feed)
}

Getting a 404 stacktrace when fetching update

Hi,
I'm using Hazel to auto-update a Windows app built with electron-forge.
autoUpdater fails to download the update a throws a 404, opening an error dialog. Any idea why?

Here's the relevant SquirrelSetup.log part:

2020-02-17 16:14:30> CheckForUpdateImpl: Downloading RELEASES file from https://myproject-hazel.now.sh/update/win32/0.1.5
2020-02-17 16:14:30> FileDownloader: Downloading url: https://myproject-hazel.now.sh/update/win32/0.1.5/RELEASES?id=myproject&localVersion=0.1.5&arch=amd64
2020-02-17 16:14:30> FileDownloader: Downloading file: https://myproject-hazel.now.sh/update/win32/0.1.5/myproject-0.1.6-full.nupkg
2020-02-17 16:14:30> IEnableLogger: Failed downloading URL: https://myproject-hazel.now.sh/update/win32/0.1.5/myproject-0.1.6-full.nupkg: System.Net.WebException: The remote server returned an error: (404) Not Found.

I don't understand why it would look for the 0.1.6 release under the 0.1.5 folder...

My update code (onReady):

  const server = "https://myproject-hazel.now.sh";
  const feed = `${server}/update/${process.platform}/${app.getVersion()}`;
  autoUpdater.setFeedURL({ url: feed });

  // Check after a few seconds seconds
  setTimeout(() => {
    // Fail if not a Squirrel-installed app
    try {
      autoUpdater.checkForUpdates();
    } catch (error) {
      // Nothing to do here.
    }
  }, 10 * 1000);

Any help would be appreciated!

Invalid urls for RELEASES file generated for windows updates

When checking the REALESES file download, with updated links to be able to download nupkg files properly, I saw that the nupkg links were not all edited, and were not mathcing the updates.

Observed behavior:

E091039C90E653AC0DCD0D74BB7C50E7DBCC8B42 https://github.com/Supamiu/ffxiv-teamcraft/releases/download/v7.0.0-beta.8/ffxiv-teamcraft-7.0.0-beta7-full.nupkg 79186641
EB4A4C0ED8595A7984EEF41E782BE87328517585 ffxiv-teamcraft-7.0.0-beta8-delta.nupkg 284017
B1FED2E7FB4CC4C94DE6A9622EFE261ECE350B45 ffxiv-teamcraft-7.0.0-beta8-full.nupkg 79014815

Expected behavior:

I expected the urls to all be replaced with the corresponding github links, so the windows updater can properly download them from github.

Error during build

I'm trying to migrate to Now v2 with a new clone of this Hazel server, my config looks like this:

now.json

{
  "version": 2,
  "name": "brandy-hazel-server",
  "alias": ["hazel-server-qrpzcymewp"],
  "builds": [
    {
      "src": "lib/server.js",
      "use": "@now/node"
    }
  ],
  "routes": [
    {
      "src": ".*",
      "dest": "/lib/server.js"
    }
  ]
}

Now CLI

now -e ACCOUNT="itsnwa" -e REPOSITORY="brandy" -e TOKEN="<access_token>" -e URL="<same_as_alias_in_config(https://hazel-server-qrpzcymewp.now.sh)>"

When I look at the log in the zeit dashboard, I get this:

START RequestId: adb906da-6a33-4c6a-80cb-4d419bea9277 Version: $LATEST
2019-08-19T17:48:22.228Z	adb906da-6a33-4c6a-80cb-4d419bea9277	Cannot find module '.'
2019-08-19T17:48:22.228Z	adb906da-6a33-4c6a-80cb-4d419bea9277	Did you forget to add it to "dependencies" in `package.json`?
END RequestId: adb906da-6a33-4c6a-80cb-4d419bea9277
REPORT RequestId: adb906da-6a33-4c6a-80cb-4d419bea9277	
Duration: 42.09 ms  Billed Duration: 100 ms   Memory Size: 3008 MB  Max Memory Used: 22 MB	
RequestId: adb906da-6a33-4c6a-80cb-4d419bea9277 Process exited before completing request

GitHub limit to 100mb

Hi everyone, I am trying to create a release using Electron Forge. It works fine but whenever I try to upload the out folder, GitHub complains that the files are too large.

How are you getting around this issue? Any help would be appreciated.

latest.yml error

Im using electron-updater;
its throwing: Cannot find channel "latest.yml" update info: HttpError: 404
config:
const { autoUpdater } = require("electron-updater") const server = "https://hazel.mineinfo80.now.sh/"; const feed = "${server}/update/${process.platform}/${app.getVersion()}";

Support .deb auto detect

Is there a way to auto detect Ubuntu / deb and download the appropriate file, like we currently have for Mac and Windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.