+40
-6
hosting-service/src/server.ts
+40
-6
hosting-service/src/server.ts
···
71
71
const requestPath = '/' + (filePath || '');
72
72
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
73
73
const cookies = parseCookies(headers?.['cookie']);
74
-
74
+
75
75
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
76
76
queryParams,
77
77
headers,
···
79
79
});
80
80
81
81
if (redirectMatch) {
82
-
const { targetPath, status } = redirectMatch;
83
-
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
+
84
101
// Handle different status codes
85
102
if (status === 200) {
86
103
// Rewrite: serve different content but keep URL the same
···
235
252
const requestPath = '/' + (filePath || '');
236
253
const queryParams = fullUrl ? parseQueryString(fullUrl) : {};
237
254
const cookies = parseCookies(headers?.['cookie']);
238
-
255
+
239
256
const redirectMatch = matchRedirectRule(requestPath, redirectRules, {
240
257
queryParams,
241
258
headers,
···
243
260
});
244
261
245
262
if (redirectMatch) {
246
-
const { targetPath, status } = redirectMatch;
247
-
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
+
248
282
// Handle different status codes
249
283
if (status === 200) {
250
284
// Rewrite: serve different content but keep URL the same