-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·47 lines (37 loc) · 1.26 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
/*! @license
* Express Chocolatey Server
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const express = require('express');
const fs = require('fs');
const chocolateyServer = require('./chocolatey-server.js');
const app = express();
const port = process.env['PORT'] || 8000;
// Express middleware that logs all requests.
function loggingMiddleware(req, res, next) {
console.log(req.method, req.path, req.query);
next();
}
(async () => {
// Log requests.
app.use(loggingMiddleware);
// Load metadata about Chocolatey packages given on the command-line.
const packagePaths = process.argv.slice(2);
if (!packagePaths.length) {
console.log('Please specify paths to Chocolatey packages.');
process.exit(1);
}
const packageMetadataList = await Promise.all(packagePaths.map((path) => {
return chocolateyServer.readPackageMetadata(path);
}));
console.log('Loaded packages:', packageMetadataList);
// Configure Chocolatey server routes at the root.
await chocolateyServer.configureRoutes(app, '/', packageMetadataList);
// Start the server.
app.listen(port, () => {
console.log(`Listening on port ${port}`)
console.log('To override the port, use the PORT environment variable.');
});
})();