Skip to content

Commit

Permalink
Handle 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg committed Jan 12, 2025
1 parent 05efbf4 commit 027587b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Deploy to AWS

on:
push:
workflow_run:
workflows: ["Ruby", "Node.js CI", "Cypress Tests"]
branches: [main]
types:
- completed

permissions:
id-token: write
Expand All @@ -12,6 +15,7 @@ jobs:
deploy:
name: Build, Push to ECR, and Deploy to Fargate
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Checkout Code
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class PagesController < ActionController::Base
def index
raise ActionController::RoutingError.new("Not Found") unless route_valid?

raw_games = Game.current.includes(:host, :current_player, :users, :winner, :cloned_from_game)
redis_data = JSON.parse(REDIS.get("users_observing_games"))

Expand All @@ -21,4 +23,10 @@ def robots
format.text { render plain: rules }
end
end

private

def route_valid?
%w[register sign_in about rules game finished_games users games cloned_games import_game forgot_password reset_password rankings].any? { |path| params[:path]&.include?(path) } || !params[:path]
end
end
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ default: &default
development:
<<: *default
database: postgres
host: db
host: localhost

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "redis"

REDIS = Redis.new(url: ENV["REDIS_URL"] || "redis://redis:6379/0")
REDIS = Redis.new(url: ENV["REDIS_URL"] || "redis://localhost:6379/0")
REDIS.set("online_users", [].to_json)
REDIS.set("users_observing_games", {}.to_json)
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

root "pages#index", as: :pages_index
get "/robots.txt", to: "pages#robots"
get "*path", to: "pages#index", format: false
get "*path", to: "pages#index", constraints: ->(req) { req.format.html? }, format: false

if Rails.env.test?
namespace :cypress do
Expand Down

0 comments on commit 027587b

Please sign in to comment.