@@ -27,6 +27,7 @@ const { LLRead } = require("../../filesystem/ll_operations/ll_read");
27
27
const { Actor, UserActorType, SiteActorType } = require ( "../../services/auth/Actor" ) ;
28
28
const APIError = require ( "../../api/APIError" ) ;
29
29
const { PermissionUtil } = require ( "../../services/auth/PermissionService" ) ;
30
+ const { default : dedent } = require ( "dedent" ) ;
30
31
31
32
const AT_DIRECTORY_NAMESPACE = '4aa6dc52-34c1-4b8a-b63c-a62b27f727cf' ;
32
33
@@ -158,6 +159,15 @@ class PuterSiteMiddleware extends AdvancedBase {
158
159
subdomain_root_path = await node . get ( 'path' ) ;
159
160
}
160
161
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
+
161
171
if ( ! subdomain_root_path || subdomain_root_path === '/' ) {
162
172
throw APIError . create ( 'forbidden' ) ;
163
173
}
@@ -170,7 +180,7 @@ class PuterSiteMiddleware extends AdvancedBase {
170
180
await target_node . fetchEntry ( ) ;
171
181
172
182
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 ) ;
174
184
}
175
185
176
186
const target_is_dir = await target_node . get ( 'type' ) === TYPE_DIRECTORY ;
@@ -180,7 +190,7 @@ class PuterSiteMiddleware extends AdvancedBase {
180
190
}
181
191
182
192
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 ) ;
184
194
}
185
195
186
196
const contentType = this . modules . mime . contentType (
@@ -317,7 +327,7 @@ class PuterSiteMiddleware extends AdvancedBase {
317
327
}
318
328
}
319
329
320
- respond_index_not_found_ ( path , req , res , next ) {
330
+ respond_html_error_ ( { path, html } , req , res , next ) {
321
331
res . status ( 404 ) ;
322
332
res . set ( 'Content-Type' , 'text/html; charset=UTF-8' ) ;
323
333
res . write ( `<div style="font-size: 20px;
@@ -328,10 +338,15 @@ class PuterSiteMiddleware extends AdvancedBase {
328
338
flex-direction: column;">` ) ;
329
339
res . write ( '<h1 style="margin:0; color:#727272;">404</h1>' ) ;
330
340
res . write ( `<p style="margin-top:10px;">` )
331
- if ( path === '/index.html' )
341
+ if ( path ) {
342
+ if ( path === '/index.html' ) {
332
343
res . write ( '<code>index.html</code> Not Found' ) ;
333
- else
344
+ } else {
334
345
res . write ( 'Not Found' ) ;
346
+ }
347
+ } else {
348
+ res . write ( html ) ;
349
+ }
335
350
res . write ( `</p>` )
336
351
337
352
res . write ( '</div>' ) ;
0 commit comments