Skip to content

Commit cfa5c7e

Browse files
committed
fix: puter subdomain error response
We were sending a JSON error in what should have been an HTML response. Additionally, the error message wasn't very clear about the nature of the problem.
1 parent ae9f5ef commit cfa5c7e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/backend/src/routers/hosting/puter-site.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const { LLRead } = require("../../filesystem/ll_operations/ll_read");
2727
const { Actor, UserActorType, SiteActorType } = require("../../services/auth/Actor");
2828
const APIError = require("../../api/APIError");
2929
const { PermissionUtil } = require("../../services/auth/PermissionService");
30+
const { default: dedent } = require("dedent");
3031

3132
const AT_DIRECTORY_NAMESPACE = '4aa6dc52-34c1-4b8a-b63c-a62b27f727cf';
3233

@@ -158,6 +159,15 @@ class PuterSiteMiddleware extends AdvancedBase {
158159
subdomain_root_path = await node.get('path');
159160
}
160161

162+
163+
if ( ! subdomain_root_path ) {
164+
return this.respond_html_error_({
165+
html: dedent(`
166+
Subdomain or site is not pointing to a directory.
167+
`),
168+
}, req, res, next);
169+
}
170+
161171
if ( ! subdomain_root_path || subdomain_root_path === '/' ) {
162172
throw APIError.create('forbidden');
163173
}
@@ -170,7 +180,7 @@ class PuterSiteMiddleware extends AdvancedBase {
170180
await target_node.fetchEntry();
171181

172182
if ( ! await target_node.exists() ) {
173-
return this.respond_index_not_found_(path, req, res, next);
183+
return this.respond_html_error_({ path }, req, res, next);
174184
}
175185

176186
const target_is_dir = await target_node.get('type') === TYPE_DIRECTORY;
@@ -180,7 +190,7 @@ class PuterSiteMiddleware extends AdvancedBase {
180190
}
181191

182192
if ( target_is_dir ) {
183-
return this.respond_index_not_found_(path, req, res, next);
193+
return this.respond_html_error_({ path }, req, res, next);
184194
}
185195

186196
const contentType = this.modules.mime.contentType(
@@ -317,7 +327,7 @@ class PuterSiteMiddleware extends AdvancedBase {
317327
}
318328
}
319329

320-
respond_index_not_found_ (path, req, res, next) {
330+
respond_html_error_ ({ path, html }, req, res, next) {
321331
res.status(404);
322332
res.set('Content-Type', 'text/html; charset=UTF-8');
323333
res.write(`<div style="font-size: 20px;
@@ -328,10 +338,15 @@ class PuterSiteMiddleware extends AdvancedBase {
328338
flex-direction: column;">`);
329339
res.write('<h1 style="margin:0; color:#727272;">404</h1>');
330340
res.write(`<p style="margin-top:10px;">`)
331-
if(path === '/index.html')
341+
if ( path ) {
342+
if ( path === '/index.html' ) {
332343
res.write('<code>index.html</code> Not Found');
333-
else
344+
} else {
334345
res.write('Not Found');
346+
}
347+
} else {
348+
res.write(html);
349+
}
335350
res.write(`</p>`)
336351

337352
res.write('</div>');

0 commit comments

Comments
 (0)