Skip to content

Commit 9ee79e5

Browse files
committed
disable example API for non-lean files
1 parent 3da875a commit 9ee79e5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

server/index.mjs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ app.use("/api/projects", async (req, res) => {
8989

9090
// `*example` has the form `mathlib-demo/MathlibLatest/Logic.lean`
9191
app.use("/api/example/:project/*example", (req, res, next) => {
92-
const filePath = path.join(
93-
req.params.project,
94-
...req.params.example.filter((it) => it.length > 0 && !it.startsWith(".")),
95-
);
96-
req.url = filePath;
97-
express.static(PROJECTS_BASE_PATH)(req, res, next);
92+
const pathComponents = req.params.example.filter((it) => it.length > 0);
93+
if (!(pathComponents[pathComponents.length - 1] ?? "").endsWith(".lean")) {
94+
res.status(400).json({ error: "Bad request" });
95+
} else {
96+
const filePath = path.join(req.params.project, ...pathComponents);
97+
req.url = filePath;
98+
express.static(PROJECTS_BASE_PATH)(req, res, next);
99+
}
98100
});
99101

100102
// `:project` is the project like `mathlib-demo`

0 commit comments

Comments
 (0)