Merge branch 'add-basic-auth' into 'master'

protect all API routes with basic auth

See merge request saburly/gangsta/roraccounting!4
This commit was merged in pull request #4.
This commit is contained in:
Senad Uka
2020-09-04 03:19:50 +00:00
8 changed files with 42 additions and 3 deletions

2
Procfile Normal file
View File

@@ -0,0 +1,2 @@
web: bundle exec rails s
release: bundle exec rails db:migrate

View File

@@ -1,3 +1,4 @@
class ApplicationController < ActionController::API
include Response
include BasicAuth
end

View File

@@ -0,0 +1,9 @@
module BasicAuth
extend ActiveSupport::Concern
included do
include ActionController::HttpAuthentication::Basic::ControllerMethods
http_basic_authenticate_with name: ENV['BASIC_AUTH_USERNAME'],
password: ENV['BASIC_AUTH_PASSWORD']
end
end

View File

@@ -0,0 +1,17 @@
class StaticController < ActionController::API
include ActionView::Layouts
include BasicAuth
def frontend_index_html
if params[:path].present?
send_file params[:path]
else
render file: 'protected_public/index.html'
end
end
def frontend_static
full_path = "protected_public/#{params[:path]}.#{params[:format]}"
send_file full_path
end
end

View File

@@ -20,7 +20,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<!-- Import Google Icon Font -->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

View File

@@ -6,7 +6,8 @@ Rails.application.routes.draw do
get 'cash'
end
end
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '*path', to: 'static#frontend_static'
root to: 'static#frontend_index_html'
end

View File

@@ -1,4 +1,13 @@
{
"engines": {
"node": "10.15.3",
"yarn": "1.15.2"
},
"scripts": {
"build": "yarn --cwd client install && yarn --cwd client build",
"deploy": "cp -a client/build/. protected_public/",
"heroku-postbuild": "yarn build && yarn deploy"
},
"dependencies": {
"react-router-dom": "^5.0.1"
}

View File