mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
17 lines
477 B
TypeScript
17 lines
477 B
TypeScript
import type { Express } from "express";
|
|
import path from "path";
|
|
|
|
export const serveOpenInEditor = (app: Express, basePath: string) => {
|
|
app.get("/open-in-editor/*", (req, res) => {
|
|
const { line, column } = req.query;
|
|
|
|
const filePath = req.path.replace("/open-in-editor", "");
|
|
|
|
const vscodeUrl = `vscode://file/${path.join(basePath, filePath)}?${
|
|
line ? `line=${line}` : ""
|
|
}${column ? `&column=${column}` : ""}`;
|
|
|
|
res.redirect(vscodeUrl);
|
|
});
|
|
};
|