From cfa5c7e715405a0f92dc798195edc25f66b2b83b Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 3 Mar 2025 13:05:09 -0500 Subject: [PATCH] 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. --- src/backend/src/routers/hosting/puter-site.js | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/backend/src/routers/hosting/puter-site.js b/src/backend/src/routers/hosting/puter-site.js index 74d7ec38..2f78bd9c 100644 --- a/src/backend/src/routers/hosting/puter-site.js +++ b/src/backend/src/routers/hosting/puter-site.js @@ -27,6 +27,7 @@ const { LLRead } = require("../../filesystem/ll_operations/ll_read"); const { Actor, UserActorType, SiteActorType } = require("../../services/auth/Actor"); const APIError = require("../../api/APIError"); const { PermissionUtil } = require("../../services/auth/PermissionService"); +const { default: dedent } = require("dedent"); const AT_DIRECTORY_NAMESPACE = '4aa6dc52-34c1-4b8a-b63c-a62b27f727cf'; @@ -158,6 +159,15 @@ class PuterSiteMiddleware extends AdvancedBase { subdomain_root_path = await node.get('path'); } + + if ( ! subdomain_root_path ) { + return this.respond_html_error_({ + html: dedent(` + Subdomain or site is not pointing to a directory. + `), + }, req, res, next); + } + if ( ! subdomain_root_path || subdomain_root_path === '/' ) { throw APIError.create('forbidden'); } @@ -170,7 +180,7 @@ class PuterSiteMiddleware extends AdvancedBase { await target_node.fetchEntry(); if ( ! await target_node.exists() ) { - return this.respond_index_not_found_(path, req, res, next); + return this.respond_html_error_({ path }, req, res, next); } const target_is_dir = await target_node.get('type') === TYPE_DIRECTORY; @@ -180,7 +190,7 @@ class PuterSiteMiddleware extends AdvancedBase { } if ( target_is_dir ) { - return this.respond_index_not_found_(path, req, res, next); + return this.respond_html_error_({ path }, req, res, next); } const contentType = this.modules.mime.contentType( @@ -317,7 +327,7 @@ class PuterSiteMiddleware extends AdvancedBase { } } - respond_index_not_found_ (path, req, res, next) { + respond_html_error_ ({ path, html }, req, res, next) { res.status(404); res.set('Content-Type', 'text/html; charset=UTF-8'); res.write(`
`); res.write('

404

'); res.write(`

`) - if(path === '/index.html') + if ( path ) { + if ( path === '/index.html' ) { res.write('index.html Not Found'); - else + } else { res.write('Not Found'); + } + } else { + res.write(html); + } res.write(`

`) res.write('
');