I am trying to connect to a HTTPS express server set up like so:
const https = require('https')
const key = fs.readFileSync('./cert/key.pem')
const cert = fs.readFileSync('./cert/cert.pem')
const server = https.createServer({key: key, cert: cert}, app)
I then configure vite.config.js to include the following:
export default defineConfig({
plugins: [sveltekit()],
server: {
https: {
key: fs.readFileSync(`${__dirname}/../server/cert/key.pem`),
cert: fs.readFileSync(`${__dirname}/../server/cert/cert.pem`)
}
}
});
However, whenever I try to connect to the server on https://localhost:5173, I get the following error:
TypeError: Headers.append: ":method" is an invalid header name.
at webidl.errors.exception (node:internal/deps/undici/undici:1635:14)
at webidl.errors.invalidArgument (node:internal/deps/undici/undici:1646:28)
at appendHeader (node:internal/deps/undici/undici:2052:29)
at fill (node:internal/deps/undici/undici:2038:11)
at new Request (node:internal/deps/undici/undici:6151:13)
at getRequest (file:///Users/jackgoodman/Desktop/pbbg/client/node_modules/@sveltejs/kit/src/exports/node/index.js:101:9)
at file:///Users/jackgoodman/Desktop/pbbg/client/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:475:27
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I have scoured the entire internet and nothing seems to be posted on this error - I have no clue what this is referring to and how it could at all be related to the https server. I'm running node v20.10.0 and the latest version of SvelteKit.
Thank you!
- Reverting to http solves the problems.
- Not sure what to try next - I don't know where svelte headers are; I used ctrl+F on "method" and get to this block in node_modules/@sveltejs/kit/src/exports/node... but I don't know what to do with this besides knowing that this may be the error source.
export async function getRequest({ request, base, bodySizeLimit }) {
return new Request(base + request.url, {
// @ts-expect-error
duplex: 'half',
method: request.method,
headers: /** @type {Record<string, string>} */ (request.headers),
body: get_raw_body(request, bodySizeLimit)
});
}
It might be a bug with SvelteKit 2. I have opened an issue on GitHub: https://github.com/sveltejs/kit/issues/11365. There is a work around that you can try for now. In your vite.config.ts: