update robots.txt

This commit is contained in:
MuslemRahimi 2024-08-13 21:47:30 +02:00
parent e8f686567e
commit d5c6d10a1a
2 changed files with 18 additions and 9 deletions

View File

@ -4,14 +4,19 @@ import { serializeNonPOJOs } from '$lib/utils';
const usRegion = new Set(['cle1', 'iad1', 'pdx1', 'sfo1']); const usRegion = new Set(['cle1', 'iad1', 'pdx1', 'sfo1']);
export const handle = async ({ event, resolve }) => { export const handle = async ({ event, resolve }) => {
// Use optional chaining and nullish coalescing for safer property access
const regionHeader = event?.request?.headers?.get('x-vercel-id') ?? 'fra1::fra1::8t4xg-1700258428633-157d82fdfcc7'; const regionHeader = event?.request?.headers?.get('x-vercel-id') ?? 'fra1::fra1::8t4xg-1700258428633-157d82fdfcc7';
const userRegion = regionHeader.split('::')[0];
// Use a more compatible way to get the first element of the split array
const userRegion = regionHeader.split('::')[0] || '';
const isUsRegion = usRegion.has(userRegion); const isUsRegion = usRegion.has(userRegion);
const pbURL = import.meta.env[isUsRegion ? 'VITE_USEAST_POCKETBASE_URL' : 'VITE_EU_POCKETBASE_URL'];
const apiURL = import.meta.env[isUsRegion ? 'VITE_USEAST_API_URL' : 'VITE_EU_API_URL']; // Use a ternary operator instead of the logical OR for better compatibility
const fastifyURL = import.meta.env[isUsRegion ? 'VITE_USEAST_FASTIFY_URL' : 'VITE_EU_FASTIFY_URL']; const pbURL = isUsRegion ? import.meta.env.VITE_USEAST_POCKETBASE_URL : import.meta.env.VITE_EU_POCKETBASE_URL;
const wsURL = import.meta.env[isUsRegion ? 'VITE_USEAST_WS_URL' : 'VITE_EU_WS_URL']; const apiURL = isUsRegion ? import.meta.env.VITE_USEAST_API_URL : import.meta.env.VITE_EU_API_URL;
const fastifyURL = isUsRegion ? import.meta.env.VITE_USEAST_FASTIFY_URL : import.meta.env.VITE_EU_FASTIFY_URL;
const wsURL = isUsRegion ? import.meta.env.VITE_USEAST_WS_URL : import.meta.env.VITE_EU_WS_URL;
event.locals = { event.locals = {
region: decodeURIComponent(regionHeader), region: decodeURIComponent(regionHeader),
@ -25,7 +30,7 @@ export const handle = async ({ event, resolve }) => {
const authCookie = event?.request?.headers?.get('cookie') || ''; const authCookie = event?.request?.headers?.get('cookie') || '';
event.locals.pb.authStore.loadFromCookie(authCookie); event.locals.pb.authStore.loadFromCookie(authCookie);
if (event.locals.pb.authStore.isValid) { if (event?.locals?.pb?.authStore?.isValid) {
try { try {
await event.locals.pb.collection('users').authRefresh(); await event.locals.pb.collection('users').authRefresh();
event.locals.user = serializeNonPOJOs(event.locals.pb.authStore.model); event.locals.user = serializeNonPOJOs(event.locals.pb.authStore.model);
@ -36,13 +41,17 @@ export const handle = async ({ event, resolve }) => {
} }
const response = await resolve(event); const response = await resolve(event);
response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({
// Use a more compatible way to set the cookie
const cookieString = event.locals.pb.authStore.exportToCookie({
httpOnly: true, httpOnly: true,
path: '/', path: '/',
sameSite: 'lax', sameSite: 'lax',
secure: true, secure: true,
maxAge: 60 * 60 * 24 * 365 maxAge: 60 * 60 * 24 * 365
})); });
response.headers.append('set-cookie', cookieString);
return response; return response;
}; };

View File

@ -1,3 +1,3 @@
# https://www.robotstxt.org/robotstxt.html # https://www.robotstxt.org/robotstxt.html
User-agent: * User-agent: *
Disallow: Disallow: /