summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTradam <[email protected]>2024-05-16 15:22:12 -0400
committerTradam <[email protected]>2024-05-16 15:22:12 -0400
commit6ae14ae3a10d79e5f0b70b1b1af74e8a3507bb83 (patch)
treeef5ed5e9277dc3c69cc938634ac1351920b91ad8
parent519568969b9ff3a47e595073a40fef099586e3c9 (diff)
downloadgameHolster-6ae14ae3a10d79e5f0b70b1b1af74e8a3507bb83.tar.gz
gameHolster-6ae14ae3a10d79e5f0b70b1b1af74e8a3507bb83.zip
isolate serving of user HTML files to a seperate domain
-rw-r--r--app/javascript/components/Layout.jsx12
-rw-r--r--config/routes.rb39
2 files changed, 35 insertions, 16 deletions
diff --git a/app/javascript/components/Layout.jsx b/app/javascript/components/Layout.jsx
index 30d1086..79e7813 100644
--- a/app/javascript/components/Layout.jsx
+++ b/app/javascript/components/Layout.jsx
@@ -5,6 +5,18 @@ export default function Layout ({userData})
{
console.log(userData);
//const [userData, setUserData] = useState({ name: "" });
+
+ // if the user tries to access the isolated domain then we redirect them
+ // this is NOT done for security, only for good UX
+ // rails serves the react app no matter what
+ // so the app would be broken when served on the isolated domain
+ const domain = window.location.host;
+ console.log(domain);
+ if(domain === "localhost:3000")
+ {
+ window.location.replace("http://127.0.0.1:3000");
+ }
+
return (
<>
<div id="page" className="star flex flex-row min-h-screen max-h-screen bg-amber-400 text-stone-950 text-xl bg-star bg-repeat bg-[length:170px_170px]">
diff --git a/config/routes.rb b/config/routes.rb
index cc5e70e..e89c5c0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -2,25 +2,32 @@ Rails.application.routes.draw do
namespace :api do
namespace :v1 do
- # USERS
- get 'users/index', to: 'users#index'
- #get 'users/new'
- #get 'users/create'
- #get 'users/delete'
+ # isolated domain, do not allow auth here
+ constraints domain: 'localhost' do
+ # GAMES
+ get 'games/*path/:file', to: 'games#index'
+ end
- # GAMES
- get 'games/*path/:file', to: 'games#index'
- #resources :games
+ constraints domain: "127.0.0.1" do
+ # USERS
+ get 'users/index', to: 'users#index'
+ #get 'users/new'
+ #get 'users/create'
+ #get 'users/delete'
- # BLOGS
- get 'blogs/index', to: 'blog#index'
- post 'blogs/create', to: 'blog#create'
- get '/show/:id', to: 'blog#show'
- delete '/destroy/:id', to: 'blog#destroy'
+ # GAMES
+ #resources :games
- # AUTH
- get 'auth/callback', to: 'auth#callback'
- get 'auth/data', to: 'auth#data'
+ # BLOGS
+ get 'blogs/index', to: 'blog#index'
+ post 'blogs/create', to: 'blog#create'
+ get '/show/:id', to: 'blog#show'
+ delete '/destroy/:id', to: 'blog#destroy'
+
+ # AUTH
+ get 'auth/callback', to: 'auth#callback'
+ get 'auth/data', to: 'auth#data'
+ end
end
end
root 'homepage#index'