enso/tools/simple-library-server/main.js

42 lines
987 B
JavaScript
Raw Normal View History

2021-06-22 14:35:15 +03:00
#!/usr/bin/env node
const express = require("express");
const compression = require("compression");
const yargs = require("yargs");
const argv = yargs
.usage(
"$0",
"Allows to host Enso libraries and editions from the local filesystem through HTTP."
)
.option("port", {
description: "The port to listen on.",
type: "number",
default: 8080,
})
.option("root", {
description:
"The root of the repository. It should contain a `libraries` or `editions` directory. See the documentation for more details.",
type: "string",
default: ".",
})
.help()
.alias("help", "h").argv;
2021-07-22 09:24:06 +03:00
const app = express();
app.use(compression({ filter: shouldCompress }));
app.use(express.static(argv.root));
2021-06-22 14:35:15 +03:00
console.log(
`Serving the repository located under ${argv.root} on port ${argv.port}.`
);
app.listen(argv.port);
function shouldCompress(req, res) {
if (req.path.endsWith(".yaml")) {
return true;
}
return compression.filter(req, res);
}