I have a React app, built with Vite, that makes use of the server section in the Vite config to allow local HTTPS:
vite.config.ts
:
...
server: {
host: true, // to support Docker
https: {
cert: './localhost+1.pem',
key: './localhost+1-key.pem',
},
...
Now I want to configure a GitHub Workflow to run the vitest tests in PR checks… this checks out, lints and builds correctly, but when it gets to the test step, I get an error:
⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
Error: error:0480006C:PEM routines::no start line
at node:internal/tls/secure-context:70:13
at Array.forEach (<anonymous>)
at setCerts (node:internal/tls/secure-context:68:3)
at configSecureContext (node:internal/tls/secure-context:186:5)
at Object.createSecureContext (node:_tls_common:116:3)
at Server.setSecureContext (node:_tls_wrap:1486:27)
at Server (node:_tls_wrap:1350:8)
at new Server (node:https:75:3)
at createServer (node:https:133:10)
at createWebSocketServer (file:///home/runner/work/repo-name/repo-name/node_modules/vite/dist/node/chunks/dep-DkOS1hkm.js:61088:28) {
library: 'PEM routines',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'
}
This seems to be because it can’t find the configured cert & key.
I’ve base64 encoded both, stored these encoded versions as secrets on the repo, and added the following to my workflow YAML file (as suggested in this GitHub discussion:
...
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install the app
run: npm ci
- name: Build the app
run: npm run build --if-present
- name: Lint the code
run: npm run lint
- name: Write Key File
env:
KEY: ${{ secrets.SSL_KEY }}
run: |
echo "$KEY" | base64 --decode > ${HOME}/localhost+1-key.pem
- name: Write Certificate File
env:
CERT: ${{ secrets.SSL_CERT }}
run: |
echo "$CERT" | base64 --decode > ${HOME}/localhost+1.pem
- name: Test the app
run: npm test
- name: Tidy up
run: rm ${HOME}/localhost+1.pem ${HOME}/localhost_1-key.pem
The output of the Write Certificate File step is:
echo "$CERT" | base64 --decode > ${HOME}/localhost+1.pem
shell: /usr/bin/bash -e {0}
env:
CERT: ***
(Of course, GitHub hides the actual cert in the logs.)
but I’m still getting the exact same error.
I’m at a loss now as to why the pem files still can’t be found… I can’t tell if it’s not creating them, or not finding them once they are properly created.