Skip to content

Commit c653aec

Browse files
authored
[fix] rename BASE to ORIGIN and fix config handling (sveltejs#3423)
1 parent 192a8fe commit c653aec

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fake-scope/fake-pkg": patch
3+
---
4+
5+
[fix] rename `BASE` to `ORIGIN` and fix config handling

packages/adapter-node/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export default {
2020
path: 'SOCKET_PATH',
2121
host: 'HOST',
2222
port: 'PORT',
23-
base: undefined,
23+
origin: 'ORIGIN',
2424
headers: {
25-
protocol: undefined,
26-
host: 'host'
25+
protocol: 'PROTOCOL_HEADER',
26+
host: 'HOST_HEADER'
2727
}
2828
}
2929
})
@@ -49,13 +49,13 @@ By default, the server will accept connections on `0.0.0.0` using port 3000. The
4949
HOST=127.0.0.1 PORT=4000 node build
5050
```
5151

52-
HTTP doesn't give SvelteKit a reliable way to know the URL that is currently being requested. The simplest way to tell SvelteKit where the app is being served is to set the `BASE` environment variable:
52+
HTTP doesn't give SvelteKit a reliable way to know the URL that is currently being requested. The simplest way to tell SvelteKit where the app is being served is to set the `ORIGIN` environment variable:
5353

5454
```
55-
BASE=https://my.site node build
55+
ORIGIN=https://my.site node build
5656
```
5757

58-
With this, a request for the `/stuff` pathname will correctly resolve to `https://my.site/stuff`. Alternatively, you can specify headers that tell SvelteKit about the request protocol and host, from which it can construct the base URL:
58+
With this, a request for the `/stuff` pathname will correctly resolve to `https://my.site/stuff`. Alternatively, you can specify headers that tell SvelteKit about the request protocol and host, from which it can construct the origin URL:
5959

6060
```
6161
PROTOCOL_HEADER=x-forwarded-proto HOST_HEADER=x-forwarded-host node build
@@ -69,7 +69,7 @@ All of these environment variables can be changed, if necessary, using the `env`
6969
env: {
7070
host: 'MY_HOST_VARIABLE',
7171
port: 'MY_PORT_VARIABLE',
72-
base: 'MY_BASEURL',
72+
origin: 'MY_ORIGINURL',
7373
headers: {
7474
protocol: 'MY_PROTOCOL_HEADER',
7575
host: 'MY_HOST_HEADER'
@@ -80,7 +80,7 @@ env: {
8080
```
8181
MY_HOST_VARIABLE=127.0.0.1 \
8282
MY_PORT_VARIABLE=4000 \
83-
MY_BASEURL=https://my.site \
83+
MY_ORIGINURL=https://my.site \
8484
node build
8585
```
8686

packages/adapter-node/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface AdapterOptions {
77
path?: string;
88
host?: string;
99
port?: string;
10-
base?: string;
10+
origin?: string;
1111
headers?: {
1212
protocol?: string;
1313
host?: string;

packages/adapter-node/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export default function ({
1717
path: path_env = 'SOCKET_PATH',
1818
host: host_env = 'HOST',
1919
port: port_env = 'PORT',
20-
base: base_env,
20+
origin: origin_env = 'ORIGIN',
2121
headers: {
2222
protocol: protocol_header_env = 'PROTOCOL_HEADER',
2323
host: host_header_env = 'HOST_HEADER'
24-
}
24+
} = {}
2525
} = {}
2626
} = {}) {
2727
return {
@@ -54,7 +54,7 @@ export default function ({
5454
PATH_ENV: JSON.stringify(path_env),
5555
HOST_ENV: JSON.stringify(host_env),
5656
PORT_ENV: JSON.stringify(port_env),
57-
BASE: base_env ? `process.env[${JSON.stringify(base_env)}]` : 'undefined',
57+
ORIGIN_ENV: origin_env ? `process.env[${JSON.stringify(origin_env)}]` : 'undefined',
5858
PROTOCOL_HEADER: JSON.stringify(protocol_header_env),
5959
HOST_HEADER: JSON.stringify(host_header_env)
6060
}

packages/adapter-node/src/handler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { getRequest, setResponse } from '@sveltejs/kit/node';
77
import { App } from 'APP';
88
import { manifest } from 'MANIFEST';
99

10-
/* global BASE_ENV, PROTOCOL_HEADER, HOST_HEADER */
10+
/* global ORIGIN_ENV, PROTOCOL_HEADER, HOST_HEADER */
1111

1212
const app = new App(manifest);
13-
const base = BASE_ENV && process.env[BASE_ENV];
13+
const origin = ORIGIN_ENV && process.env[ORIGIN_ENV];
1414
const protocol_header = PROTOCOL_HEADER && process.env[PROTOCOL_HEADER];
1515
const host_header = (HOST_HEADER && process.env[HOST_HEADER]) || 'host';
1616

@@ -39,7 +39,7 @@ const ssr = async (req, res) => {
3939
let request;
4040

4141
try {
42-
request = await getRequest(base || get_base(req.headers), req);
42+
request = await getRequest(origin || get_origin(req.headers), req);
4343
} catch (err) {
4444
res.statusCode = err.status || 400;
4545
return res.end(err.reason || 'Invalid request body');
@@ -68,7 +68,7 @@ function sequence(handlers) {
6868
* @param {import('http').IncomingHttpHeaders} headers
6969
* @returns
7070
*/
71-
function get_base(headers) {
71+
function get_origin(headers) {
7272
const protocol = (protocol_header && headers[protocol_header]) || 'https';
7373
const host = headers[host_header];
7474
return `${protocol}://${host}`;

packages/adapter-node/src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ declare global {
22
const PATH_ENV: string;
33
const HOST_ENV: string;
44
const PORT_ENV: string;
5-
const BASE_ENV: string;
5+
const ORIGIN_ENV: string;
66

77
const PROTOCOL_HEADER: string;
88
const HOST_HEADER: string;

0 commit comments

Comments
 (0)