Skip to content
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

fix(gatsby): fix --https option for develop #36248

Merged
merged 1 commit into from
Jul 27, 2022
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
2 changes: 0 additions & 2 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ module.exports = async (program: IProgram): Promise<void> => {
port: developPort,
// TODO(v5): remove
proxyPort: developPort,
// Don't pass SSL options down to the develop process, it should always use HTTP
ssl: null,
debugInfo,
})};
cmd(args);
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Store, AnyAction } from "redux"
import { IGatsbyState } from "../redux/types"

export interface ICert {
key: Buffer
cert: Buffer
key: string
cert: string
Comment on lines -6 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are passing ICert Object to child process, so this has to be serializable. Buffer can be serialized but but this was fastest way to fix as Strings are also supported.

Without this I was getting:

The "options.cert" property must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object

}

export interface IDebugInfo {
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/utils/get-ssl-cert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export async function getSslCert({
? absoluteOrDirectory(directory, caFile)
: certPath
return {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
key: fs.readFileSync(keyPath, `utf-8`),
cert: fs.readFileSync(certPath, `utf-8`),
}
}

Expand Down Expand Up @@ -98,8 +98,8 @@ export async function getSslCert({
process.env.NODE_EXTRA_CA_CERTS = caPath
}
return {
key,
cert,
key: key.toString(),
cert: cert.toString(),
}
} catch (err) {
report.panic({
Expand Down
7 changes: 5 additions & 2 deletions packages/gatsby/src/utils/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "graphql"
import { slash, uuid } from "gatsby-core-utils"
import http from "http"
import https from "https"
import cors from "cors"
import telemetry from "gatsby-telemetry"
import launchEditor from "react-dev-utils/launchEditor"
Expand Down Expand Up @@ -59,7 +60,7 @@ type ActivityTracker = any // TODO: Replace this with proper type once reporter

interface IServer {
compiler: webpack.Compiler
listener: http.Server
listener: http.Server | https.Server
webpackActivity: ActivityTracker
websocketManager: WebsocketManager
workerPool: WorkerPool.GatsbyWorkerPool
Expand Down Expand Up @@ -799,7 +800,9 @@ export async function startServer(
/**
* Set up the HTTP server and socket.io.
**/
const server = new http.Server(app)
const server = program.ssl
? new https.Server(program.ssl, app)
: new http.Server(app)
const socket = websocketManager.init({ server })
const listener = server.listen(program.port, program.host)

Expand Down