Express Chocolatey Server
A simple Chocolatey package server for Express.
Designed to host packages for https://github.com/shaka-project/shaka-lab
If you need to serve Chocolatey packages, and the
other options
look too complicated, this is the server for you.
It doesn't require Windows, it doesn't require .NET, it can be deployed
anywhere you can use Express, and it can be
integrated into other Express-based servers. It is not a full nuget v2 API
implementation, nor a full odata implementation. Rather, it implements the
bare minimum to interact with the Chocolatey client.
You can use the standalone server CLI to serve the packages themselves as well
as their metadata. Or, if you want to host the package files separately, you
can use the module as a library and provide the package metadata.
Standalone server
If you want to host the actual package files in the same server, this is the
easiest way to use express-chocolatey-server. You can use our standalone
server CLI, and provide paths to all the packages you want to serve.
PORT=8000 npx express-chocolatey-server *.nupkg
Simple App Engine deployment
Start by placing your nupkg files, package.json (see below), and app.yaml (also
below) in a folder.
package.json:
{
"dependencies": {
"express-chocolatey-server": "^1.0.0"
},
"scripts": {
"start": "express-chocolatey-server *.nupkg"
},
"engines": {
"node": "16.x.x"
}
}
app.yaml:
runtime: nodejs16
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
Then deploy to App Engine with:
gcloud app deploy app.yaml --project=MY_PROJECT_ID_GOES_HERE
Configuring clients
The client needs to add your server as a new "source". Each source has a name.
If you want your source to be named "my-awesome-packages" and your server is
running at "http://10.0.0.2:8000/", you would configure your choco clients with:
choco source add -n=my-awesome-packages -s=http://10.0.0.2:8000/
Hosting packages separately
The library provides two methods:
function readPackageMetadata(path)
: Reads a single nupkg file and returns
metadata extracted from it.
async function configureRoutes(app, prefix, packageMetadataList)
: Sets up
Express routes for a Chocolatey server under the given prefix, and serves
metadata for the packages listed.
If you want to host the packages separately from the Express server, you will
want to pre-computing the package metadata, rather than maintaining it by hand.
const chocolateyServer = require('express-chocolatey-server');
(async () => {
const packagePaths = process.argv.slice(2);
const packageMetadataList = await Promise.all(packagePaths.map((path) => {
return chocolateyServer.readPackageMetadata(path);
}));
console.log(JSON.stringify(packageMetadataList));
});
const express = require('express');
const chocolateyServer = require('express-chocolatey-server');
const app = express();
const port = process.env['PORT'] || 8000;
(async () => {
const packageMetadataList = require('package-metadata.json');
await chocolateyServer.configureRoutes(app, '/', packageMetadataList);
app.listen(port, () => {
console.log(`Listening on port ${port}`)
});
})();