fix: BUG-009 setTimeout syntax, BUG-010 CORS helmet policy, BUG-011 content-type validation
This commit is contained in:
parent
6891e488b6
commit
d8bc3fd8e6
3 changed files with 8 additions and 2 deletions
|
|
@ -67,7 +67,7 @@ function copyKey() {
|
||||||
var key = document.getElementById('apiKeyDisplay').textContent;
|
var key = document.getElementById('apiKeyDisplay').textContent;
|
||||||
navigator.clipboard.writeText(key).then(function() {
|
navigator.clipboard.writeText(key).then(function() {
|
||||||
var btn = document.getElementById('apiKeyDisplay'); var origText = btn.textContent; btn.textContent = 'Copied!'; document.querySelector('.copy-hint').textContent = '✓ Copied!';
|
var btn = document.getElementById('apiKeyDisplay'); var origText = btn.textContent; btn.textContent = 'Copied!'; document.querySelector('.copy-hint').textContent = '✓ Copied!';
|
||||||
setTimeout(function() { btn.textContent = origText; document.querySelector('.copy-hint').textContent = 'Click to copy';
|
setTimeout(function() { btn.textContent = origText; document.querySelector('.copy-hint').textContent = 'Click to copy'; }, 2000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const PORT = parseInt(process.env.PORT || "3100", 10);
|
||||||
// Load API keys from persistent store
|
// Load API keys from persistent store
|
||||||
loadKeys();
|
loadKeys();
|
||||||
|
|
||||||
app.use(helmet());
|
app.use(helmet({ crossOriginResourcePolicy: { policy: "cross-origin" } }));
|
||||||
|
|
||||||
// CORS — allow browser requests from the landing page
|
// CORS — allow browser requests from the landing page
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,12 @@ interface ConvertBody {
|
||||||
// POST /v1/convert/html
|
// POST /v1/convert/html
|
||||||
convertRouter.post("/html", async (req: Request, res: Response) => {
|
convertRouter.post("/html", async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
|
// Reject non-JSON content types
|
||||||
|
const ct = req.headers["content-type"] || "";
|
||||||
|
if (!ct.includes("application/json")) {
|
||||||
|
res.status(415).json({ error: "Unsupported Content-Type. Use application/json." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const body: ConvertBody =
|
const body: ConvertBody =
|
||||||
typeof req.body === "string" ? { html: req.body } : req.body;
|
typeof req.body === "string" ? { html: req.body } : req.body;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue