Bug fix when refreshing page
This commit is contained in:
@@ -34,6 +34,7 @@ export default {
|
||||
|
||||
// 1. Check if request is coming from git
|
||||
if (userAgent.toLowerCase().includes('git')) {
|
||||
console.info("Redirecting to Chookspace, as useragent is Git");
|
||||
const redirectUrl = new URL(url.toString());
|
||||
redirectUrl.hostname = 'chookspace.com';
|
||||
return Response.redirect(redirectUrl.toString(), 302);
|
||||
@@ -47,6 +48,7 @@ export default {
|
||||
// Need at least user and repo
|
||||
// Otherwise, redirect to profile
|
||||
if (parts.length < 2) {
|
||||
console.info("Redirecting to Chookspace, not a long enough request");
|
||||
const redirectUrl = new URL(url.toString());
|
||||
redirectUrl.hostname = 'chookspace.com';
|
||||
return Response.redirect(redirectUrl.toString(), 302);
|
||||
@@ -68,6 +70,8 @@ export default {
|
||||
const rawBase = `https://chookspace.com/${user}/${repo}/raw/branch/master/chookspace`;
|
||||
const rawUrl = `${rawBase}/${filePath}`;
|
||||
|
||||
console.log("Raw URL: ", rawUrl);
|
||||
|
||||
try {
|
||||
// Prepare headers for the fetch request
|
||||
const fetchHeaders = new Headers(request.headers);
|
||||
@@ -78,9 +82,11 @@ export default {
|
||||
headers: fetchHeaders,
|
||||
redirect: 'follow'
|
||||
});
|
||||
console.info("Response from Chookspace was", rawResponse.status);
|
||||
|
||||
// 4. If success (2xx), proxy it
|
||||
if (rawResponse.ok) {
|
||||
if (rawResponse.status >= 200 && rawResponse.status < 400) {
|
||||
console.info("Proxying page");
|
||||
const mimeType = getMimeType(filePath);
|
||||
|
||||
// Create new headers to override Content-Type
|
||||
@@ -99,6 +105,7 @@ export default {
|
||||
}
|
||||
|
||||
// 5. If not found or error, redirect to chookspace site
|
||||
console.info("Redirecting to Chookspace normally...");
|
||||
const redirectUrl = new URL(url.toString());
|
||||
redirectUrl.hostname = 'chookspace.com';
|
||||
return Response.redirect(redirectUrl.toString(), 302);
|
||||
|
||||
Reference in New Issue
Block a user