Skip to content

Commit

Permalink
fix extract domain from referer
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Feb 12, 2024
1 parent 0b7f805 commit 5df93f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { extractDomain } from '../auth-routes-builder';

describe('auth route builder', () => {
it('should be able to extract a domain from an url', () => {
let url = 'https://www.google.com';
let domain = extractDomain(url);
expect(domain).toBe('google.com');

url = 'http://www.google.com';
domain = extractDomain(url);
expect(domain).toBe('google.com');

url = 'http://google.com';
domain = extractDomain(url);
expect(domain).toBe('google.com');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type PassportCallbackAuthenticateMiddlewareOptions = {
failureRedirect: string;
};

const extractDomain = (url) => {
const domain = url.match(/^(?:https|http?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
export const extractDomain = (url) => {
const domain = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
return domain;
};

Expand Down

0 comments on commit 5df93f4

Please sign in to comment.