Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions __tests__/redirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ describe('GET /r/:postId', () => {
return request(app.server)
.get('/r/p1')
.expect(302)
.expect('Location', 'http://p1.com/?ref=dailydev');
.expect('Location', 'http://p1.com/?via=dailydev');
});

it('should redirect to youtube post url', () => {
return request(app.server)
.get('/r/yt1')
.expect(302)
.expect('Location', 'https://youtu.be/T_AbQGe7fuU?ref=dailydev');
.expect('Location', 'https://youtu.be/T_AbQGe7fuU?via=dailydev');
});

it('should render redirect html and notify view event', async () => {
Expand All @@ -61,9 +61,9 @@ describe('GET /r/:postId', () => {
.expect(200)
.expect('content-type', 'text/html')
.expect('referrer-policy', 'origin, origin-when-cross-origin')
.expect('link', `<http://p1.com/?ref=dailydev>; rel="preconnect"`)
.expect('link', `<http://p1.com/?via=dailydev>; rel="preconnect"`)
.expect(
'<html><head><meta name="robots" content="noindex,nofollow"><meta http-equiv="refresh" content="0;URL=http://p1.com/?ref=dailydev"></head></html>',
'<html><head><meta name="robots" content="noindex,nofollow"><meta http-equiv="refresh" content="0;URL=http://p1.com/?via=dailydev"></head></html>',
);
expect(notifyView).toBeCalledWith(
expect.anything(),
Expand All @@ -82,9 +82,9 @@ describe('GET /r/:postId', () => {
.expect(200)
.expect('content-type', 'text/html')
.expect('referrer-policy', 'origin, origin-when-cross-origin')
.expect('link', `<http://p1.com/?ref=dailydev>; rel="preconnect"`)
.expect('link', `<http://p1.com/?via=dailydev>; rel="preconnect"`)
.expect(
'<html><head><meta name="robots" content="noindex,nofollow"><meta http-equiv="refresh" content="0;URL=http://p1.com/?ref=dailydev#id"></head></html>',
'<html><head><meta name="robots" content="noindex,nofollow"><meta http-equiv="refresh" content="0;URL=http://p1.com/?via=dailydev#id"></head></html>',
);
});

Expand All @@ -95,7 +95,7 @@ describe('GET /r/:postId', () => {
return request(app.server)
.get('/r/p1')
.expect(302)
.expect('Location', 'http://p1.com/?a=b&ref=dailydev');
.expect('Location', 'http://p1.com/?a=b&via=dailydev');
});

it('should redirect to post page when url is not available', async () => {
Expand All @@ -118,7 +118,7 @@ describe('GET /r/:postId', () => {
.expect(302)
.expect(
'Location',
'http://p1.com/hello%20world/%f0%9f%9a%80-to-the-%F0%9F%8C%94?ref=dailydev',
'http://p1.com/hello%20world/%f0%9f%9a%80-to-the-%F0%9F%8C%94?via=dailydev',
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/routes/redirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function (fastify: FastifyInstance): Promise<void> {
return res.status(302).redirect(getDiscussionLink(post.slug));
}
const url = new URL(post.url);
url.searchParams.append('ref', 'dailydev');
url.searchParams.append('via', 'dailydev');
const encodedUri = encodeUrl(url.href);
if (req.isBot) {
return res.status(302).redirect(encodedUri);
Expand Down
Loading