Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 5, 2024
1 parent ffd0642 commit 80276a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
16 changes: 1 addition & 15 deletions solara/lib/core/dashboard/dashboard_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,9 @@ def create_server
@server = WEBrick::HTTPServer.new(
Port: @port,
DocumentRoot: @root,
DirectoryIndex: ['local.html'],
Logger: logger
)

@server.mount_proc '/' do |req, res|
path = req.path == '/' ? '/index.html' : req.path
file_path = File.join(@root, path)

if File.exist?(file_path) && !File.directory?(file_path)
res.body = File.read(file_path)
res['Content-Type'] = WEBrick::HTTPUtils.mime_type(file_path, WEBrick::HTTPUtils::DefaultMimeTypes)
else
res.status = 404
end

# Add the source=local parameter to all responses
res['Location'] = "#{req.path}?source=local" if res.status == 302
end
rescue StandardError => e
Solara.logger.failure("Error creating server: #{e.message}")
exit(1)
Expand Down
28 changes: 3 additions & 25 deletions solara/lib/core/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,9 @@
}
</style>
<script>
// Function to get query parameters
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}

// Get the source from the query parameter, default to 'local'
const source = getQueryParameter('source') || 'local';

if (source === 'local') {
fetch('/redirect')
.then(response => response.json())
.then(data => {
setTimeout(() => {
window.location.href = data.redirect_url;
}, 500);
})
.catch(error => console.error('Error:', error));
} else if (source === 'remote') {
setTimeout(() => {
window.location.href = 'brands/brands.html?source=remote';
}, 500);
} else {
console.error('Invalid source parameter');
}
setTimeout(() => {
window.location.href = 'brands/brands.html?source=remote';
}, 500);
</script>
</head>
<body>
Expand Down

0 comments on commit 80276a9

Please sign in to comment.