From 027587bb084e7a2796c933847543adfd349eca99 Mon Sep 17 00:00:00 2001 From: Eric Tillberg Date: Sun, 12 Jan 2025 15:46:56 -0500 Subject: [PATCH] Handle 404s --- .github/workflows/deploy.yml | 6 +++++- app/controllers/pages_controller.rb | 8 ++++++++ config/database.yml | 2 +- config/initializers/redis.rb | 2 +- config/routes.rb | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b236df64..46556e30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 @@ -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 diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index c8bdac56..3aa8c657 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -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")) @@ -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 diff --git a/config/database.yml b/config/database.yml index e6ccddab..b8bb0c98 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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`. diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb index 2e88afe9..bc865e4f 100644 --- a/config/initializers/redis.rb +++ b/config/initializers/redis.rb @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 51db029d..2f7d6fc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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