Local HTTPS
The local HTTPS functions serve your Vite dev server on a trusted HTTPS origin that customer account login accepts. Use these functions to provision local certificates and to sync your development URLs to the Customer Account API settings.
Import localHttps, provisionLocalHttps, and LOCAL_HTTPS_DEFAULTS from @shopify/hydrogen/vite.
Anchor to Vite pluginVite plugin
Serves your Vite dev server over trusted HTTPS on a fixed host and port, and adds the dev server URLs to your Customer Account API settings. Vite exits when another process uses the port. The dev server speaks HTTP/1.1 only.
When vite dev starts without certificate files, the plugin asks for permission in the terminal, then creates the files. The plugin skips the prompt without an interactive terminal and in CI. Hydrogen treats any CI environment variable value other than an empty string, false, or 0 as CI. While certificate files are missing, the plugin prints a warning and leaves HTTPS off.
After the dev server starts, the plugin runs Shopify CLI to update your Customer Account API settings with the dev server URLs. The update needs a Shopify CLI that includes 13.0.4 or later. When the project has no linked Hydrogen storefront, Shopify CLI asks you to link one first. When Shopify CLI is missing or outdated, or the update fails, the plugin prints the URLs to enter by hand and the dev server keeps running. In CI, the plugin prints the URLs and skips Shopify CLI.
Anchor to localHttps-parametersParameters
- Anchor to optionsoptionsoptionsLocalHttpsOptionsLocalHttpsOptionsrequiredrequired
Switch, host, port, and certificate paths for local HTTPS.
Anchor to localHttps-returnsReturns
A Vite plugin. Its
method returns the HTTPS settings for frameworks that serve HTTPS outside Vite.
LocalHttpsOptions
Switch, host, port, and certificate files for local HTTPS.
- certPath
Path to the certificate file. Defaults to `~/.shopify/hydrogen/certs/<host>.pem`. A leading `~/` points to your home directory, and a relative path starts from the current working directory.
string | URL - enabled
Turns on local HTTPS for the dev server. When `false`, the plugin leaves the Vite config unchanged.
boolean - host
Hostname for the dev server and the Customer Account API URLs. Defaults to `local.tryhydrogen.dev`.
string - keyPath
Path to the private key file. Defaults to `~/.shopify/hydrogen/certs/<host>-key.pem`. Accepts the same path forms as `certPath`.
string | URL - port
Port for the dev server. Vite exits when another process uses the port. Defaults to `5173`.
number
LocalHttpsPlugin
The local HTTPS Vite plugin, with an API for frameworks that start their own HTTPS server.
Plugin & LocalHttpsPluginExtensionLocalHttpsPluginExtension
The API that the local HTTPS Vite plugin adds to the Vite plugin object.
- api
Methods for frameworks that start their own HTTPS server.
LocalHttpsPluginApi
LocalHttpsPluginApi
Methods for frameworks that start their own HTTPS server.
- getDevServerConfig
Returns the host, port, and certificate paths for frameworks that serve HTTPS outside Vite, such as Nuxt. Returns `undefined` when `enabled` is `false` or a certificate file is missing.
() => LocalHttpsDevServerConfig
LocalHttpsDevServerConfig
Host, port, and certificate file paths for serving local HTTPS outside Vite.
- host
Local hostname that the dev server serves, such as `local.tryhydrogen.dev`.
string - https
Absolute paths to the certificate file and the private key file.
{ cert: string; key: string; } - port
Port for the dev server.
number
TypeScript
Examples
Description
Add the plugin to a Vite config. This example enables HTTPS only when Vite starts through the `dev:https` package script.
TypeScript
import { localHttps } from "@shopify/hydrogen/vite"; import { defineConfig } from "vite"; export default defineConfig({ plugins: [ localHttps({ enabled: process.env.npm_lifecycle_event === "dev:https", }), ], });Description
Register the plugin with Vite and pass its dev server config to Nuxt. This example lets Nitro terminate HTTPS with the plugin's certificates.
TypeScript
import { localHttps } from "@shopify/hydrogen/vite"; import type { NuxtConfig } from "nuxt/schema"; type VitePlugin = NonNullable<NonNullable<NuxtConfig["vite"]>["plugins"]>[number]; const httpsPlugin = localHttps({ enabled: process.env.npm_lifecycle_event === "dev:https", }); export default defineNuxtConfig({ devServer: httpsPlugin.api.getDevServerConfig(), vite: { plugins: [httpsPlugin as VitePlugin], }, });
Anchor to Certificate provisioningCertificate provisioning
Creates trusted certificate files for local HTTPS. Call the function from a setup script, or before you start a framework that reads certificate paths when its config loads, such as Nuxt.
When both files exist, the function returns their paths and changes nothing. Otherwise, the function downloads a pinned, checksum-verified mkcert release, adds the mkcert certificate authority to your system trust store, and creates the certificate and private key. mkcert can ask for your password.
Anchor to provisionLocalHttps-parametersParameters
- Anchor to optionsoptionsoptionsProvisionLocalHttpsOptionsProvisionLocalHttpsOptionsDefault: {}Default: {}
Host and certificate paths. Each option has a Hydrogen default.
ProvisionLocalHttpsOptions
Host and certificate paths for provisionLocalHttps.
- certPath
Path to the certificate file. Defaults to `~/.shopify/hydrogen/certs/<host>.pem`. A leading `~/` points to your home directory, and a relative path starts from the current working directory.
string | URL - host
Hostname for the dev server and the Customer Account API URLs. Defaults to `local.tryhydrogen.dev`.
string - keyPath
Path to the private key file. Defaults to `~/.shopify/hydrogen/certs/<host>-key.pem`. Accepts the same path forms as `certPath`.
string | URL
TypeScript
Examples
Description
Provision the default certificates from a script. This example prints the host and the certificate and key paths.
TypeScript
import { provisionLocalHttps } from "@shopify/hydrogen/vite"; const { host, certPath, keyPath } = await provisionLocalHttps(); console.log(`Local HTTPS is ready for https://${host}`); console.log(` Certificate: ${certPath}`); console.log(` Private key: ${keyPath}`);
Anchor to Development workflowDevelopment workflow
- Enable the plugin in a dedicated
dev:httpsscript, and keepvite devon HTTP for work that doesn't need customer account login. - Next.js apps don't use the plugin. Start Next.js with
next dev --experimental-https --hostname local.tryhydrogen.dev --port 5173, and configure the Customer Account API URLs in the Shopify admin by hand. - Astro sets the dev server host and port itself. Pass the host and port from
LOCAL_HTTPS_DEFAULTSto Astro'sserveroption. - Nuxt and SolidStart read certificate paths when the config loads. Run
npx hydrogen certs installbefore the first start, or restart once after the plugin provisions certificates.