-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTTPS and HTTP/2 support for
adapter-node
- Loading branch information
1 parent
a71d783
commit 114a589
Showing
4 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-node': minor | ||
--- | ||
|
||
feat: add opt-in HTTPS and HTTP/2 support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import { handler } from 'HANDLER'; | ||
import { env } from 'ENV'; | ||
import polka from 'polka'; | ||
import http from 'node:http'; | ||
import https from 'node:https'; | ||
import http2 from 'node:http2'; | ||
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); | ||
|
||
const server = polka().use(handler); | ||
const app = polka().use(handler); | ||
|
||
server.listen({ path, host, port }, () => { | ||
console.log(`Listening on ${path ? path : host + ':' + port}`); | ||
}); | ||
if (!only_https) { | ||
http.createServer(app.handler).listen({ path, host, port }, () => { | ||
console.log(`Listening on http://${path ? path : host + ':' + port}`); | ||
}); | ||
} | ||
|
||
export { server }; | ||
if (cert_path && cert_key_path) { | ||
const cert = fs.readFileSync(cert_path); | ||
const key = fs.readFileSync(cert_key_path); | ||
const https_server = no_http2 | ||
? https.createServer({ cert, key }, app.handler) | ||
: http2.createSecureServer({ allowHTTP1: true, cert, key }, app.handler); | ||
|
||
https_server.listen({ path, host, https_port }, () => { | ||
console.log(`Listening on https://${path ? path : host + ':' + https_port}`); | ||
}); | ||
} | ||
|
||
export { app as server }; |