+40
-6
hosting-service/src/server.ts
+40
-6
hosting-service/src/server.ts
···
71
const requestPath = '/' + (filePath || '');
72
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
73
const cookies = parseCookies(headers?.['cookie']);
74
-
75
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
76
queryParams,
77
headers,
···
79
});
80
81
if (redirectMatch) {
82
-
const { targetPath, status } = redirectMatch;
83
-
84
// Handle different status codes
85
if (status === 200) {
86
// Rewrite: serve different content but keep URL the same
···
235
const requestPath = '/' + (filePath || '');
236
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
237
const cookies = parseCookies(headers?.['cookie']);
238
-
239
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
240
queryParams,
241
headers,
···
243
});
244
245
if (redirectMatch) {
246
-
const { targetPath, status } = redirectMatch;
247
-
248
// Handle different status codes
249
if (status === 200) {
250
// Rewrite: serve different content but keep URL the same
···
71
const requestPath = '/' + (filePath || '');
72
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
73
const cookies = parseCookies(headers?.['cookie']);
74
+
75
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
76
queryParams,
77
headers,
···
79
});
80
81
if (redirectMatch) {
82
+
const { rule, targetPath, status } = redirectMatch;
83
+
84
+
// If not forced, check if the requested file exists before redirecting
85
+
if (!rule.force) {
86
+
// Build the expected file path
87
+
let checkPath = filePath || 'index.html';
88
+
if (checkPath.endsWith('/')) {
89
+
checkPath += 'index.html';
90
+
}
91
+
92
+
const cachedFile = getCachedFilePath(did, rkey, checkPath);
93
+
const fileExistsOnDisk = await fileExists(cachedFile);
94
+
95
+
// If file exists and redirect is not forced, serve the file normally
96
+
if (fileExistsOnDisk) {
97
+
return serveFileInternal(did, rkey, filePath);
98
+
}
99
+
}
100
+
101
// Handle different status codes
102
if (status === 200) {
103
// Rewrite: serve different content but keep URL the same
···
252
const requestPath = '/' + (filePath || '');
253
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
254
const cookies = parseCookies(headers?.['cookie']);
255
+
256
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
257
queryParams,
258
headers,
···
260
});
261
262
if (redirectMatch) {
263
+
const { rule, targetPath, status } = redirectMatch;
264
+
265
+
// If not forced, check if the requested file exists before redirecting
266
+
if (!rule.force) {
267
+
// Build the expected file path
268
+
let checkPath = filePath || 'index.html';
269
+
if (checkPath.endsWith('/')) {
270
+
checkPath += 'index.html';
271
+
}
272
+
273
+
const cachedFile = getCachedFilePath(did, rkey, checkPath);
274
+
const fileExistsOnDisk = await fileExists(cachedFile);
275
+
276
+
// If file exists and redirect is not forced, serve the file normally
277
+
if (fileExistsOnDisk) {
278
+
return serveFileInternalWithRewrite(did, rkey, filePath, basePath);
279
+
}
280
+
}
281
+
282
// Handle different status codes
283
if (status === 200) {
284
// Rewrite: serve different content but keep URL the same