mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): url shortener pass redirects (#65879)
This commit is contained in:
+15
-3
@@ -67,16 +67,28 @@ When you visit `/api/shorturl/<short_url>`, you will be redirected to the origin
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(`${postResponse.status} ${postResponse.statusText}`);
|
throw new Error(`${postResponse.status} ${postResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
// Ensure a new URL is reached
|
||||||
const getResponse = await fetch(
|
const getResponse = await fetch(
|
||||||
url + '/api/shorturl/' + shortenedUrlVariable
|
url + '/api/shorturl/' + shortenedUrlVariable, {redirect:'follow'}
|
||||||
);
|
);
|
||||||
if (getResponse) {
|
if (getResponse) {
|
||||||
const { redirected, url } = getResponse;
|
const { url } = getResponse; // status is always 200 for some reason
|
||||||
assert.isTrue(redirected);
|
|
||||||
assert.strictEqual(url,fullUrl);
|
assert.strictEqual(url,fullUrl);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`${getResponse.status} ${getResponse.statusText}`);
|
throw new Error(`${getResponse.status} ${getResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No more auto follow
|
||||||
|
const getManualResponse = await fetch(
|
||||||
|
url + '/api/shorturl/' + shortenedUrlVariable, {redirect:'manual'}
|
||||||
|
);
|
||||||
|
if (getManualResponse) {
|
||||||
|
const { status } = getManualResponse; // if a redirect happens, it won't reach the new resource
|
||||||
|
assert.strictEqual(status,0);
|
||||||
|
} else {
|
||||||
|
throw new Error(`${getManualResponse.status} ${getManualResponse.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you pass an invalid URL that doesn't follow the valid `http://www.example.com` format, the JSON response will contain `{ error: 'invalid url' }`
|
If you pass an invalid URL that doesn't follow the valid `http://www.example.com` format, the JSON response will contain `{ error: 'invalid url' }`
|
||||||
|
|||||||
Reference in New Issue
Block a user