Problem
When a WebSocket app is created with createEndpoint and no envVars are provided, the SDK HTTP server handler returns 426 Upgrade Required for all HTTP requests -- including the OPTIONS probe that jambonz sends to discover application environment variables.
This causes confusing behavior in the jambonz portal (e.g. Invalid appenv schema errors) and forces developers to manually add an HTTP request handler:
const server = http.createServer((req, res) => {
res.writeHead(405, {"Content-Type": "text/plain"});
res.end("Method Not Allowed");
});
const makeService = createEndpoint({server, port: 3000});
Proposed Fix
When envVars is not provided (or is undefined), the SDK should handle the HTTP request event on the server and return 405 Method Not Allowed (or 404) by default, rather than 426 Upgrade Required. This way apps without env vars just work without needing a manual HTTP handler.
The current code in createEndpoint already handles the envVars case:
server.on("request", (req, res) => {
if (req.method === "OPTIONS" && envVars) {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(envVars));
return;
}
res.writeHead(426, { "Content-Type": "text/plain" });
res.end("Upgrade Required");
});
The fallback 426 should be changed to 405 so that the portal (and any other HTTP client) gets a clean response indicating no env vars are available.