mcp-connector
Version:
MCP Remote Proxy Server for Streamable HTTP with OAuth Support.
53 lines • 1.87 kB
JavaScript
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export class HTMLRenderer {
templatesPath;
constructor() {
this.templatesPath = join(__dirname, "../../templates");
}
renderSuccessPage(baseUrl, stateAuthCompleted = false) {
try {
let template = readFileSync(join(this.templatesPath, "success.html"), "utf-8");
template = template.replace(/{{baseUrl}}/g, baseUrl);
const authCompletedMsg = stateAuthCompleted
? '<span style="margin-left:8px; color:#388e3c; font-weight:500;">(Already Authenticated)</span>'
: "";
template = template.replace(/{{AlreadyAuthenticated}}/g, authCompletedMsg);
return template;
}
catch {
return this.getFallbackSuccessPage(baseUrl);
}
}
renderErrorPage(title, message) {
try {
const template = readFileSync(join(this.templatesPath, "error.html"), "utf-8");
return template
.replace(/{{title}}/g, title)
.replace(/{{message}}/g, message);
}
catch {
return this.getFallbackErrorPage(title, message);
}
}
getFallbackSuccessPage(baseUrl) {
return `<!DOCTYPE html>
<html><head><title>Authentication Successful</title></head>
<body><h1>Success!</h1>
<p>Authenticated with ${baseUrl}</p>
<p>You can close this window.</p>
</body></html>`;
}
getFallbackErrorPage(title, message) {
return `<!DOCTYPE html>
<html><head><title>${title}</title></head>
<body><h1>${title}</h1>
<p>${message}</p>
<p>Please close this window and try again.</p>
</body></html>`;
}
}
//# sourceMappingURL=html-renderer.js.map