Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 404s #879

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ["Pre-Deploy Status Check"]
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
24 changes: 24 additions & 0 deletions .github/workflows/pre_deploy_status_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pre-Deploy Status Check

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

jobs:
check-statuses:
runs-on: ubuntu-latest
steps:
- name: Check Workflow Statuses
run: |
required_workflows=("Ruby" "Node.js CI" "Cypress Tests")
for workflow in "${required_workflows[@]}"; do
status=$(gh run list --workflow "$workflow" --branch main --json conclusion -q '.[0].conclusion')
echo "$workflow: $status"
if [[ "$status" != "success" ]]; then
echo "Workflow $workflow did not succeed. Aborting deployment."
exit 1
fi
done
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
Loading