Skip to content

Commit e2c75cb

Browse files
committed
fix(server): avoid overriding env variables
1 parent d88a38e commit e2c75cb

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

__tests__/runtime/route.test.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe('constructContext function', () => {
191191
expect(typeof context.getTwilioClient).toBe('function');
192192
});
193193

194-
test('overrides existing PATH', () => {
194+
test('does not override existing PATH values', () => {
195195
const env: EnvironmentVariablesWithAuth = {
196196
ACCOUNT_SID: 'ACxxxxxxxxxxx',
197197
AUTH_TOKEN: 'xyz',
@@ -203,11 +203,22 @@ describe('constructContext function', () => {
203203
env,
204204
} as StartCliConfig;
205205
const context = constructContext(config, '/test2');
206-
expect(context.DOMAIN_NAME).toBe('localhost:8000');
207-
expect(context.PATH).toBe('/test2');
208-
expect(context.ACCOUNT_SID).toBe('ACxxxxxxxxxxx');
209-
expect(context.AUTH_TOKEN).toBe('xyz');
210-
expect(typeof context.getTwilioClient).toBe('function');
206+
expect(context.PATH).toBe('/usr/bin:/bin');
207+
});
208+
209+
test('does not override existing DOMAIN_NAME values', () => {
210+
const env: EnvironmentVariablesWithAuth = {
211+
ACCOUNT_SID: 'ACxxxxxxxxxxx',
212+
AUTH_TOKEN: 'xyz',
213+
DOMAIN_NAME: 'hello.world',
214+
};
215+
216+
const config = {
217+
url: 'http://localhost:8000',
218+
env,
219+
} as StartCliConfig;
220+
const context = constructContext(config, '/test2');
221+
expect(context.DOMAIN_NAME).toBe('hello.world');
211222
});
212223

213224
test('getTwilioClient calls twilio constructor', () => {

src/runtime/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function constructContext<T extends {} = {}>(
4646
}
4747
const DOMAIN_NAME = url.replace(/^https?:\/\//, '');
4848
const PATH = functionPath;
49-
return { ...env, DOMAIN_NAME, PATH, getTwilioClient };
49+
return { PATH, DOMAIN_NAME, ...env, getTwilioClient };
5050
}
5151

5252
export function constructGlobalScope(config: StartCliConfig): void {

0 commit comments

Comments
 (0)