diff --git a/documentation/docs/25-build-and-deploy/40-adapter-node.md b/documentation/docs/25-build-and-deploy/40-adapter-node.md index 1e4bf8490ed7..fdb464d33d17 100644 --- a/documentation/docs/25-build-and-deploy/40-adapter-node.md +++ b/documentation/docs/25-build-and-deploy/40-adapter-node.md @@ -116,6 +116,8 @@ The files are read once on startup, so if the contents of the files change, the The default port that will be used for the HTTPS endpoint is 3001. You can customize this via the `HTTPS_PORT` environment variable. +> We generally recommend you use a reverse proxy in front of your application to enable HTTPS instead, and have your reverse proxy communicate with your SvelteKit application via plain HTTP; only use these options when you know what you're doing, or as a last resort. + ### `NO_HTTP2`: By default, the HTTPS endpoint will support HTTP/2 as well as HTTP/1.1. If, for some reason, supporting HTTP/2 isn't desirable, you can disable it by setting the `NO_HTTP2` environment variable to a non-empty value (e.g. `1`). diff --git a/packages/adapter-node/src/index.js b/packages/adapter-node/src/index.js index 9a2ccc205876..5122a59dc9f3 100644 --- a/packages/adapter-node/src/index.js +++ b/packages/adapter-node/src/index.js @@ -9,15 +9,15 @@ import fs from 'node:fs'; export const path = env('SOCKET_PATH', false); export const host = env('HOST', '0.0.0.0'); export const port = env('PORT', !path && '3000'); -export const cert_path = env('CERT_PATH', false); -export const cert_key_path = env('CERT_KEY_PATH', false); -export const https_port = env('HTTPS_PORT', !path && '3001'); -export const only_https = env('ONLY_HTTPS', false); -export const no_http2 = env('NO_HTTP2', false); +export const certPath = env('CERT_PATH', false); +export const certKeyPath = env('CERT_KEY_PATH', false); +export const httpsPort = env('HTTPS_PORT', !path && '3001'); +export const onlyHttps = env('ONLY_HTTPS', false); +export const noHttp2 = env('NO_HTTP2', false); const app = polka().use(handler); -if (!only_https) { +if (!onlyHttps) { // TODO Remove the `@ts-expect-error`s below once https://github.com/lukeed/polka/issues/194 is fixed // @ts-expect-error http.createServer(app.handler).listen({ path, host, port }, () => { @@ -25,17 +25,17 @@ if (!only_https) { }); } -if (cert_path && cert_key_path) { - const cert = fs.readFileSync(cert_path); - const key = fs.readFileSync(cert_key_path); - const https_server = no_http2 +if (certPath && certKeyPath) { + const cert = fs.readFileSync(certPath); + const key = fs.readFileSync(certKeyPath); + const https_server = noHttp2 ? // @ts-expect-error https.createServer({ cert, key }, app.handler) : // @ts-expect-error http2.createSecureServer({ allowHTTP1: true, cert, key }, app.handler); - https_server.listen({ path, host, port: https_port }, () => { - console.log(`Listening on https://${path ? path : host + ':' + https_port}`); + https_server.listen({ path, host, port: httpsPort }, () => { + console.log(`Listening on https://${path ? path : host + ':' + httpsPort}`); }); }