The following web app is written in Node.js and shows how to set up a simple proxy server for Keygen Dist, allowing you to use your own domain name for serving product releases.
This example application is not 100% production-ready, but it should get you 90% of the way there. You may need to add additional logging, error handling, validation, features, etc.
First up, configure a few environment variables:
# Your Keygen account ID.
export KEYGEN_ACCOUNT_ID="YOUR_KEYGEN_ACCOUNT_ID"
# The Keygen product which this proxy is serving releases for.
export KEYGEN_PRODUCT_ID="YOUR_KEYGEN_PRODUCT_ID"
# The Keygen policy that allows a user the ability to download
# a release or receive an update, e.g. this could be your 'Pro'
# policy, or simply a general policy used for your licenses.
export KEYGEN_POLICY_ID="YOUR_KEYGEN_POLICY_ID"
You can either run each line above within your terminal session before
starting the app, or you can add the above contents to your ~/.bashrc
file and then run source ~/.bashrc
after saving the file.
Next, install dependencies with yarn
:
yarn
Then start the app:
yarn start
For local development, create an ngrok
tunnel:
ngrok http 8080
You can now make requests to any of the following routes:
This will download an update release for a given platform depending on the user's current version. See the download update endpoint for Keygen Dist.
This will download the latest release for a given platform. See the download latest release endpoint for Keygen Dist.
This will download a release by filename for a given platform. See the download release endpoint for Keygen Dist.
If you'd like to automatically detect a user's platform, that's as simple as
implementing a little bit of extra logic using something like the express-useragent
package:
const userAgent = require('express-useragent')
const ua = userAgent.parse(req.headers['user-agent'])
let platform
if (ua.isMac) {
platform = 'darwin'
} else if (ua.isWindows) {
platform = 'win32'
} else if (us.isLinux) {
platform = 'linux'
} else {
// … handle other platforms
}
Reach out at support@keygen.sh if you have any questions or concerns!