make Dev Center aware of the origin of the host environment

This commit is contained in:
Nariman Jelveh 2024-07-07 20:43:57 -07:00
parent ad56091c2f
commit 594424444a
3 changed files with 37 additions and 7 deletions

View File

@ -245,7 +245,7 @@
<script src="./js/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script src="./js/jquery.dragster.js"></script>
<script src="https://js.puter.com/v2/"></script>
<script src="/puter.js/v2"></script>
<script src="./js/slugify.js"></script>
<script type="module" src="./js/html-entities.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

View File

@ -56,6 +56,28 @@ if (URLParams.has('puter.domain')) {
domain = URLParams.get('puter.domain')
}
// static hosting domain
let static_hosting_domain = 'puter.site';
if(domain === 'puter.localhost'){
static_hosting_domain = 'site.puter.localhost';
}
if (URLParams.has('puter.port') && URLParams.get('puter.port')) {
static_hosting_domain = static_hosting_domain + `:` + URLParams.get('puter.port');
}
// protocol
let protocol = 'https';
if (URLParams.has('puter.protocol')) {
protocol = URLParams.get('puter.protocol');
}
// port
let port = '';
if (URLParams.has('puter.port') && URLParams.get('puter.port')) {
port = URLParams.get('puter.port');
}
$(document).ready(function () {
$('#loading').show();
@ -244,7 +266,7 @@ async function create_app(title, source_path = null, items = null) {
puter.apps.update(app.name, {
title: title,
name: name,
indexURL: source_path ? `https://${name}.puter.site` : 'https://dev-center.puter.com/coming-soon.html',
indexURL: source_path ? protocol + `://${name}.` + static_hosting_domain : 'https://dev-center.puter.com/coming-soon.html',
icon: icon,
description: ' ',
maximizeOnStart: false,
@ -375,7 +397,7 @@ $(document).on('click', '.delete-app', async function (e) {
// generate app link
function applink(app) {
return `https://${domain}/app/${app.name}`;
return protocol + `://${domain}${ port ? ':' + port : '' }/app/${app.name}`;
}
//----------------------------------------------------
@ -1279,7 +1301,7 @@ window.deploy = async function (app, items) {
puter.hosting.create(hostname, appdata_dir.path).then(async (res) => {
// TODO this endpoint needs to be able to update only the specified fields
puter.apps.update(currently_editing_app.name, {
indexURL: `https://${hostname}.puter.site`,
indexURL: protocol + `://${hostname}.` + static_hosting_domain,
title: currently_editing_app.title,
name: currently_editing_app.name,
icon: currently_editing_app.icon,
@ -1289,7 +1311,7 @@ window.deploy = async function (app, items) {
filetypeAssociations: currently_editing_app.filetype_associations,
})
// set the 'Index URL' field for the 'Settings' tab
$('#edit-app-index-url').val(`https://${hostname}.puter.site`);
$('#edit-app-index-url').val(protocol + `://${hostname}.` + static_hosting_domain);
// show success message
$('.deploy-success-msg').show();
// reset drop area
@ -1323,7 +1345,7 @@ window.deploy = async function (app, items) {
puter.hosting.create(hostname, appdata_dir.path).then(async (res) => {
// TODO this endpoint needs to be able to update only the specified fields
puter.apps.update(currently_editing_app.name, {
indexURL: `https://${hostname}.puter.site`,
indexURL: protocol + `://${hostname}.` + static_hosting_domain,
title: currently_editing_app.title,
name: currently_editing_app.name,
icon: currently_editing_app.icon,
@ -1333,7 +1355,7 @@ window.deploy = async function (app, items) {
filetypeAssociations: currently_editing_app.filetype_associations,
})
// set the 'Index URL' field for the 'Settings' tab
$('#edit-app-index-url').val(`https://${hostname}.puter.site`);
$('#edit-app-index-url').val(protocol + `://${hostname}.` + static_hosting_domain);
// show success message
$('.deploy-success-msg').show();
// reset drop area

View File

@ -224,6 +224,14 @@ const launch_app = async (options)=>{
iframe_url.searchParams.append('puter.domain', window.app_domain);
// get URL parts
const url = new URL(window.location.href);
iframe_url.searchParams.append('puter.origin', url.origin);
iframe_url.searchParams.append('puter.hostname', url.hostname);
iframe_url.searchParams.append('puter.port', url.port);
iframe_url.searchParams.append('puter.protocol', url.protocol.slice(0, -1));
if(window.api_origin)
iframe_url.searchParams.append('puter.api_origin', window.api_origin);