Skip to content

feat: add SSL support #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ GCS_CLIENT_EMAIL=
GCS_PRIVATE_KEY=
# Azure Blob Storage
ABS_CONNECTION_STRING=
# HTTPS
HTTP2=
SSL_KEY_PATH=
SSL_CERT_PATH=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ junit-testresults.xml
.DS_Store
build
.envrc

# Certs, if placed locally for testing
**/certs
4 changes: 4 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ nav_order: 2
| `STORAGE_PATH_USE_TMP_FOLDER` | boolean | optional | `true` | Uses the system tmp folder as a prefix to `STORAGE_PATH` |
| `BODY_LIMIT` | number | optional | `104857600` | The limit for artifact upload size |
| `HTTP2` | boolean | optional | `'false'` | If set to `true`, the server will use the HTTP/2 protocol, which helps bypass the 32MB payload size limit in Cloud Run |
| `SSL_KEY_PATH` | string | optional | `` | If set, enables HTTPS using the key file at the specified path. |
| `SSL_CERT_PATH` | string | optional | `` | If set, enables HTTPS using the certificate file at the specified path. |

Both `SSL_KEY_PATH` and `SSL_CERT_PATH` must be set to enable HTTPS.
17 changes: 17 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'node:fs'
import { isBoom } from '@hapi/boom'
import Fastify, { FastifyInstance, FastifyServerOptions } from 'fastify'
import hyperid from 'hyperid'
Expand All @@ -11,9 +12,25 @@ const uuid = hyperid({ urlSafe: true })
export function createApp(
options: FastifyServerOptions & { configOverrides?: Partial<Config> } = {},
): FastifyInstance {
const SSL_CERT_PATH = env.get().SSL_CERT_PATH
const SSL_KEY_PATH = env.get().SSL_KEY_PATH
const isHttps =
SSL_CERT_PATH &&
SSL_KEY_PATH &&
fs.existsSync(SSL_CERT_PATH) &&
fs.existsSync(SSL_KEY_PATH)

const fastifyOptions: FastifyServerOptions = {
...options,
...(env.get().HTTP2 ? { http2: true } : {}),
...(isHttps
? {
https: {
key: fs.readFileSync(SSL_KEY_PATH),
cert: fs.readFileSync(SSL_CERT_PATH),
},
}
: {}),
}

const hasConfiguredLogger =
Expand Down
4 changes: 4 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const schema = Type.Object(

// Azure Blob Storage credentials
ABS_CONNECTION_STRING: Type.Optional(Type.String()),

// SSL support
SSL_KEY_PATH: Type.Optional(Type.String()),
SSL_CERT_PATH: Type.Optional(Type.String()),
},
{
additionalProperties: false,
Expand Down
Loading