Fixed linting/prettier errors

This commit is contained in:
Jonathan Barrow
2023-01-08 09:08:49 -05:00
parent ec4539f667
commit 13a4d0c8cc

View File

@@ -5,7 +5,9 @@ const corsHeaders = {
}; };
async function handleRequest(oRequest, destination, iteration = 0) { async function handleRequest(oRequest, destination, iteration = 0) {
console.log(`PROXYING ${destination}${iteration ? ' ON ITERATION ' + iteration : ''}`); console.log(
`PROXYING ${destination}${iteration ? ' ON ITERATION ' + iteration : ''}`,
);
// Create a new mutable request object for the destination // Create a new mutable request object for the destination
const request = new Request(destination, oRequest); const request = new Request(destination, oRequest);
@@ -32,13 +34,19 @@ async function handleRequest(oRequest, destination, iteration = 0) {
// Set PHPSESSID cookie // Set PHPSESSID cookie
if (request.headers.get('PHPSESSID')) { if (request.headers.get('PHPSESSID')) {
request.headers.set('Cookie', `PHPSESSID=${request.headers.get('PHPSESSID')}`); request.headers.set(
'Cookie',
`PHPSESSID=${request.headers.get('PHPSESSID')}`,
);
} }
// Set User Agent, if not exists // Set User Agent, if not exists
const useragent = request.headers.get('User-Agent'); const useragent = request.headers.get('User-Agent');
if (!useragent) { if (!useragent) {
request.headers.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0'); request.headers.set(
'User-Agent',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0',
);
} }
// Fetch the new resource // Fetch the new resource
@@ -53,13 +61,17 @@ async function handleRequest(oRequest, destination, iteration = 0) {
if (iteration > 5) { if (iteration > 5) {
return event.respondWith( return event.respondWith(
new Response('418 Too many redirects', { new Response('418 Too many redirects', {
status: 418 status: 418,
}), }),
); );
} }
// Handle and return the request for the redirected destination // Handle and return the request for the redirected destination
return await handleRequest(request, oResponse.headers.get('location'), iteration + 1); return await handleRequest(
request,
oResponse.headers.get('location'),
iteration + 1,
);
} }
// Create mutable response using the original response as init // Create mutable response using the original response as init
@@ -78,7 +90,11 @@ async function handleRequest(oRequest, destination, iteration = 0) {
} }
// Set PHPSESSID cookie // Set PHPSESSID cookie
if (cookiesToSet && cookiesToSet.includes('PHPSESSID') && cookiesToSet.includes(';')) { if (
cookiesToSet &&
cookiesToSet.includes('PHPSESSID') &&
cookiesToSet.includes(';')
) {
let phpsessid = cookies.slice(cookies.search('PHPSESSID') + 10); let phpsessid = cookies.slice(cookies.search('PHPSESSID') + 10);
phpsessid = phpsessid.slice(0, phpsessid.search(';')); phpsessid = phpsessid.slice(0, phpsessid.search(';'));
@@ -97,8 +113,8 @@ function handleOptions(request) {
const headers = request.headers; const headers = request.headers;
let response = new Response(null, { let response = new Response(null, {
headers: { headers: {
Allow: 'GET, HEAD, POST, OPTIONS' Allow: 'GET, HEAD, POST, OPTIONS',
} },
}); });
if ( if (
@@ -111,8 +127,10 @@ function handleOptions(request) {
...corsHeaders, ...corsHeaders,
// Allow all future content Request headers to go back to browser // Allow all future content Request headers to go back to browser
// such as Authorization (Bearer) or X-Client-Name-Version // such as Authorization (Bearer) or X-Client-Name-Version
'Access-Control-Allow-Headers': request.headers.get('Access-Control-Request-Headers') 'Access-Control-Allow-Headers': request.headers.get(
} 'Access-Control-Request-Headers',
),
},
}); });
} }
@@ -127,7 +145,7 @@ addEventListener('fetch', (event) => {
console.log(`HTTP ${request.method} - ${request.url}`); console.log(`HTTP ${request.method} - ${request.url}`);
let response = new Response('404 Not Found', { let response = new Response('404 Not Found', {
status: 404 status: 404,
}); });
if (request.method === 'OPTIONS') { if (request.method === 'OPTIONS') {
@@ -139,7 +157,7 @@ addEventListener('fetch', (event) => {
headers: { headers: {
Allow: 'GET, HEAD, POST, OPTIONS', Allow: 'GET, HEAD, POST, OPTIONS',
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
} },
}); });
} else if ( } else if (
request.method === 'GET' || request.method === 'GET' ||