Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export function init(options: NextjsOptions): void {
const activeDomain = domain.active;
domain.active = null;

if (typeof options.tunnel !== 'undefined') {
try {
new URL(options.tunnel);
} catch (error) {
__DEBUG_BUILD__ &&
logger.error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
throw new Error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
}
}
nodeInit(options);

const filterTransactions: EventProcessor = event => {
Expand Down
18 changes: 18 additions & 0 deletions packages/nextjs/test/index.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ describe('Server init()', () => {
});
});

it('should not fail on valid tunnel option', () => {
expect(() =>
init({
dsn: 'https://[email protected]/12312012',
tunnel: 'https://example.com/api',
}),
).not.toThrowError();
});

it('should fail on invalid tunnel option', () => {
expect(() =>
init({
dsn: 'https://[email protected]/12312012',
tunnel: '/invalid',
}),
).toThrowError('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
});

describe('integrations', () => {
// Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
type ModifiedInitOptions = { integrations: Integration[] };
Expand Down