setup-cgi-core
Setup cgi-core
Use this skill to safely and quickly set up cgi-core for CGI script hosting.
Workflow
- Confirm runtime/platform and deployment shape (CLI-only, embedded HTTP server, or framework integration).
- Install
cgi-core. - Configure
urlPath,filePath, and interpreterextensions. - Add operational settings (timeouts, buffers, logging, status pages, env).
- Validate behavior with local requests and security checks.
Required discovery questions
Collect these before editing:
- Package manager (
npm,pnpm,yarn). - OS/runtime target (
Linux/macOS/Windows, Node version). - Hosting mode:
npx cgi-serverCLI- embedded
node:httpserver - integration in existing app/router
- CGI scripts directory path (for example
./cgi-bin). - Languages/interpreters required (
perl,python,node, etc.). - Need for reverse proxy behavior (
trustProxy) and whether proxy is trusted. - Request/response size and timeout expectations.
If details are missing, choose practical defaults and call them out.
Install
Use:
npm install cgi-core --ignore-scripts
For quick local bootstrapping:
npx cgi-server --filePath ./cgi-bin
Baseline embedded server
Use this default server shape (ESM):
import { createServer } from "node:http";
import { createHandler } from "cgi-core";
const handler = createHandler({
urlPath: "/cgi-bin",
filePath: "./cgi-bin",
extensions: {
"/usr/bin/perl": ["pl", "cgi"],
"/usr/bin/python": ["py"],
"/usr/local/bin/node": ["js", "node"],
},
debugOutput: false,
});
const app = createServer(async (req, res) => {
const requestHandled = await handler(req, res);
if (!requestHandled) {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("outside of urlPath");
}
});
app.listen(3000);
Configuration guidance
Tune these based on user needs:
urlPath: base CGI route, default/cgi-bin.filePath: scripts root; strongly prefer explicit path.extensions: map interpreters to extensions.- On Windows, recommend absolute interpreter paths for reliability/perf.
indexExtension: extension used for directory index scripts (jsby default).debugOutput: enable only during debugging.logRequests: enable for local troubleshooting.maxBuffer: cap payload sizes for safer resource use.requestChunkSize/responseChunkSize: chunking/perf tradeoff knobs.requestTimeout: set strict timeout to prevent hanging requests.statusPages: custom responses for codes like 404/500.env: static object or updater function per request.trustProxy: enable only behind trusted reverse proxy.
Proxy and security guardrails
When trustProxy is requested:
- Confirm the app is behind a trusted reverse proxy.
- Explain header spoofing risk if exposed directly to the public internet.
- Prefer fixed/validated proxy header handling in infra config.
Always keep filePath constrained to intended CGI directory and avoid dynamic user-controlled script paths.
CLI usage pattern
Use this when the user wants a lightweight standalone server:
npx cgi-server --port 3001 --urlPath /cgi-bin --filePath ./cgi-bin
Common flags to mention:
--indexExtension--maxBuffer--requestChunkSize--responseChunkSize--requestTimeout--trustProxy--debugOutput--logRequests
Reverse proxy note
If user asks about Nginx/front proxy:
- Recommend reverse proxy for TLS/static caching/perimeter controls.
- Keep warning that local example configs are not production-safe as-is.
- Emphasize static backend
Hostusage in production to avoid spoofing/cache issues.
Validation checklist
After setup, confirm:
cgi-coreappears in dependencies.- Server starts and listens on expected port.
- A script under
filePathexecutes correctly viaurlPath. - Non-CGI routes still behave as intended.
- Timeouts/buffer limits behave as expected for test payloads.
trustProxyis disabled unless trusted proxy is confirmed.
Note: Whenever you start a server for validation, ensure you stop the process once the check is complete. Do not leave background processes hanging in the user's environment.
Troubleshooting
- 404/route misses:
- Check
urlPathand script location underfilePath.
- Check
- Script not executable:
- Verify interpreter mapping in
extensionsor script shebang/permissions.
- Verify interpreter mapping in
- Large payload errors:
- Increase
maxBufferand review chunk sizes.
- Increase
- Slow/hanging requests:
- Lower
requestTimeout, inspect script runtime and upstream dependencies.
- Lower
- Incorrect client/protocol metadata:
- Re-check
trustProxyassumptions and proxy headers.
- Re-check
Output format
Return results in this structure:
- Install command(s) run.
- Files changed and why.
- Final
createHandler(...)or CLI configuration. - Verification commands/URLs used.
- Security notes (especially
trustProxyand path constraints).
More from lfortin/skills
setup-os-monitor
Install and configure the Node.js `os-monitor` package, including legacy-version fallback, threshold tuning, event handlers, stream mode, and validation. Use this skill whenever the user asks to set up OS/system monitoring in Node.js, wire alerts for memory/load/disk/uptime, or integrate `os-monitor` into an app, even if they do not explicitly mention the package name.
10create-stellar-system
Use this skill when the user asks to design, simulate, or document a physically coherent stellar system, including stars, planets, orbital stability, thermal zones, and chemical composition/distribution for worldbuilding or hard-sci-fi settings.
10