Move default function code/environment to constants file

This commit is contained in:
Peter Stockings
2025-07-23 21:51:33 +10:00
parent 19d855fb89
commit b5acb9e93e
2 changed files with 33 additions and 32 deletions

32
constants.py Normal file
View File

@@ -0,0 +1,32 @@
DEFAULT_FUNCTION_NAME = 'foo'
DEFAULT_SCRIPT = """async (req) => {
console.log(`Method:${req.method}`)
console.log(`Generating ${environment.lines} random lines...`)
let svgContent = "";
for (let i = 0; i < environment.lines; i++) {
console.log(i)
let pathD = "M2 " + Math.random() * 79;
let circles = "";
for (let x = 12; x <= 202; x += 10) {
let y = Math.random() * 79
pathD += ` L${x} ${y}`;
circles += `<circle cx="${x}" cy="${y}" r="1"></circle>`;
}
let pathColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
svgContent += `
<g style="fill: ${pathColor}; stroke: ${pathColor};">
<path d="${pathD}" fill="none" stroke="${pathColor}"></path>
${circles}
</g>`;
}
return HtmlResponse(`<svg viewBox="0 0 204 79" preserveAspectRatio="none">${svgContent}</svg>`);
}"""
DEFAULT_ENVIRONMENT = """{
"lines": 3
}"""