Skip to content

Commit fb1e2f2

Browse files
committed
feat: start directory index frame
1 parent 581964b commit fb1e2f2

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

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

+35-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ const { LLRead } = require("../../filesystem/ll_operations/ll_read");
2727
const { Actor, UserActorType, SiteActorType } = require("../../services/auth/Actor");
2828
const APIError = require("../../api/APIError");
2929

30+
const AT_DIRECTORY_NAMESPACE = '4aa6dc52-34c1-4b8a-b63c-a62b27f727cf';
31+
3032
class PuterSiteMiddleware extends AdvancedBase {
3133
static MODULES = {
3234
path: require('path'),
3335
mime: require('mime-types'),
36+
uuidv5: require('uuid').v5,
3437
}
3538
install (app) {
3639
app.use(this.run.bind(this));
@@ -66,9 +69,39 @@ class PuterSiteMiddleware extends AdvancedBase {
6669

6770
const context = Context.get();
6871
const services = context.get('services');
72+
73+
const get_username_site = (async () => {
74+
if ( ! subdomain.endsWith('.at') ) return;
75+
const parts = subdomain.split('.');
76+
if ( parts.length !== 2 ) return;
77+
const username = parts[0];
78+
if ( ! username.match(config.username_regex) ) {
79+
return;
80+
}
81+
const svc_fs = services.get('filesystem');
82+
const index_node = await svc_fs.node(new NodePathSelector(
83+
`/${username}/Public/index.html`
84+
));
85+
const node = await svc_fs.node(new NodePathSelector(
86+
`/${username}/Public`
87+
));
88+
if ( ! await index_node.exists() ) return;
89+
90+
return {
91+
name: username + '.at',
92+
uuid: this.modules.uuidv5(username, AT_DIRECTORY_NAMESPACE),
93+
root_dir_id: await node.get('mysql-id'),
94+
};
95+
})
96+
97+
const site =
98+
await get_username_site() ||
99+
await (async () => {
100+
const svc_puterSite = services.get('puter-site');
101+
const site = await svc_puterSite.get_subdomain(subdomain);
102+
return site;
103+
})();
69104

70-
const svc_puterSite = services.get('puter-site');
71-
const site = await svc_puterSite.get_subdomain(subdomain);
72105
if ( site === null ) {
73106
return res.status(404).send('Subdomain not found');
74107
}

packages/backend/src/services/PuterHomepageService.js

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class PuterHomepageService extends BaseService {
7575
app_name_regex: config.app_name_regex,
7676
app_name_max_length: config.app_name_max_length,
7777
app_title_max_length: config.app_title_max_length,
78+
hosting_domain: config.static_hosting_domain +
79+
(config.pub_port !== 80 && config.pub_port !== 443 ? ':' + config.pub_port : ''),
7880
subdomain_regex: config.subdomain_regex,
7981
subdomain_max_length: config.subdomain_max_length,
8082
domain: config.domain,

packages/backend/src/services/WebServerService.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ class WebServerService extends BaseService {
314314
// Validate host header against allowed domains to prevent host header injection
315315
// https://www.owasp.org/index.php/Host_Header_Injection
316316
app.use((req, res, next)=>{
317-
const allowedDomains = [config.domain.toLowerCase(), config.static_hosting_domain.toLowerCase()];
317+
const allowedDomains = [
318+
config.domain.toLowerCase(),
319+
config.static_hosting_domain.toLowerCase(),
320+
'at.' + config.static_hosting_domain.toLowerCase(),
321+
];
318322

319323
// Retrieve the Host header and ensure it's in a valid format
320324
const hostHeader = req.headers.host;

0 commit comments

Comments
 (0)