Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 03657db

Browse files
authored
Merge pull request #174 from textbook/feat-single-artifact-deploy
Allow running the app as a single artifact
2 parents c66431d + 07fe4f8 commit 03657db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+614
-303
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
package
1+
last-release/
2+
package/
3+
tmp/
24
package.zip
5+
last-release.zip
36
.idea/
47
.DS_Store
58
node_modules/

api/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ vendor
2626
/.idea
2727
postfacto-api.iml
2828
db/schema.rb
29+
30+
# Ignore public client files
31+
/client

api/Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gem 'jbuilder'
4545
gem 'premailer-rails', '>= 1.10.2'
4646
gem 'puma'
4747
gem 'rack-cors', require: 'rack/cors'
48+
gem 'rack-ssl'
4849
gem 'rest-client'
4950
gem 'uglifier'
5051
gem 'jwt'

api/Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ GEM
189189
puma (3.12.0)
190190
rack (2.0.7)
191191
rack-cors (1.0.2)
192+
rack-ssl (1.4.1)
193+
rack
192194
rack-test (1.1.0)
193195
rack (>= 1.0, < 3)
194196
rails (5.2.3)
@@ -339,6 +341,7 @@ DEPENDENCIES
339341
pry-byebug
340342
puma
341343
rack-cors
344+
rack-ssl
342345
rails (>= 5.2.2.1)
343346
redis (~> 3.3.3)
344347
rest-client
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Postfacto, a free, open-source and self-hosted retro tool aimed at helping
3+
# remote teams.
4+
#
5+
# Copyright (C) 2016 - Present Pivotal Software, Inc.
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
#
9+
# it under the terms of the GNU Affero General Public License as
10+
#
11+
# published by the Free Software Foundation, either version 3 of the
12+
#
13+
# License, or (at your option) any later version.
14+
#
15+
#
16+
#
17+
# This program is distributed in the hope that it will be useful,
18+
#
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
#
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
#
23+
# GNU Affero General Public License for more details.
24+
#
25+
#
26+
#
27+
# You should have received a copy of the GNU Affero General Public License
28+
#
29+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
30+
#
31+
class StaticController < ApplicationController
32+
def home
33+
render file: 'client/index.html', layout: false
34+
end
35+
end

api/client/.gitkeep

Whitespace-only changes.

api/config.ru

+38-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
1+
#
2+
# Postfacto, a free, open-source and self-hosted retro tool aimed at helping
3+
# remote teams.
4+
#
5+
# Copyright (C) 2016 - Present Pivotal Software, Inc.
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
#
9+
# it under the terms of the GNU Affero General Public License as
10+
#
11+
# published by the Free Software Foundation, either version 3 of the
12+
#
13+
# License, or (at your option) any later version.
14+
#
15+
#
16+
#
17+
# This program is distributed in the hope that it will be useful,
18+
#
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
#
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
#
23+
# GNU Affero General Public License for more details.
24+
#
25+
#
26+
#
27+
# You should have received a copy of the GNU Affero General Public License
28+
#
29+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
30+
#
131
# This file is used by Rack-based servers to start the application.
232

333
require_relative 'config/environment'
434

5-
run Rails.application
35+
if ENV['RAILS_ENV'] == 'production'
36+
require 'rack/ssl'
637

7-
require 'rack/cors'
8-
unless ENV['RAILS_ENV'] == 'production'
9-
use Rack::Cors do
10-
# allow all origins in development
11-
allow do
12-
origins '*'
13-
resource '*',
14-
headers: :any,
15-
methods: [:get, :patch, :post, :delete, :put, :options]
16-
end
17-
end
38+
use Rack::SSL,
39+
exclude: (lambda do |env|
40+
env['HTTP_CONNECTION'] == 'Upgrade' && env['HTTP_UPGRADE'] == 'websocket'
41+
end)
1842
end
43+
44+
run Rails.application

api/config/application.rb

+9
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,14 @@ class Application < Rails::Application
5252
# Application configuration should go into files in config/initializers
5353
# -- all .rb files in that directory are automatically loaded.
5454
config.autoload_paths << Rails.root.join('lib', 'configurations')
55+
if ENV['RAILS_ENV'] != 'production' || ENV['RAILS_SERVE_STATIC_FILES'].present?
56+
config.middleware.insert_after(
57+
ActionDispatch::Static,
58+
ActionDispatch::Static,
59+
Rails.root.join('client').to_s,
60+
index: config.public_file_server.index_name,
61+
headers: config.public_file_server.headers || {}
62+
)
63+
end
5564
end
5665
end

api/config/environments/development.rb

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@
8484
# routes, locales, etc. This feature depends on the listen gem.
8585
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
8686

87-
config.middleware.insert_before 0, Rack::Cors do
88-
allow do
89-
origins 'http://localhost:3000'
90-
resource '*', headers: :any, methods: [:get, :post, :patch, :delete, :options, :put]
91-
end
92-
end
93-
9487
config.after_initialize do
9588
Bullet.enable = true
9689
Bullet.bullet_logger = true

api/config/environments/test.rb

-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@
6969

7070
config.action_cable.allowed_request_origins = [/.*/]
7171

72-
config.middleware.insert_before 0, Rack::Cors do
73-
allow do
74-
origins 'http://localhost:3000'
75-
resource '*', headers: :any, methods: [:get, :post, :patch, :delete, :options, :put]
76-
end
77-
end
78-
7972
# Raises error for missing translations
8073
# config.action_view.raise_on_missing_translations = true
8174

api/config/routes.rb

+23-17
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,32 @@
3232
devise_for :admin_users, ActiveAdmin::Devise.config
3333
ActiveAdmin.routes(self)
3434

35-
put '/retros/:id/archive', to: 'retros#archive'
36-
patch '/retros/:id/password', to: 'retros#update_password', as: :retro_update_password
35+
scope '/api' do
36+
put '/retros/:id/archive', to: 'retros#archive'
37+
patch '/retros/:id/password', to: 'retros#update_password', as: :retro_update_password
3738

38-
get '/config', to: 'config#show'
39+
get '/config', to: 'config#show'
3940

40-
resources :oauth_sessions, path: 'sessions', only: [:create]
41-
resources :users, only: [:create]
41+
resources :oauth_sessions, path: 'sessions', only: [:create]
42+
resources :users, only: [:create]
4243

43-
resources :retros, only: [:index, :create, :show, :update] do
44-
resources :archives, only: [:index, :show]
45-
resources :settings, only: [:index]
46-
resources :action_items, only: [:create, :destroy, :update]
47-
resources :items, only: [:create, :update, :destroy] do
48-
patch 'done', to: :done, controller: 'items'
49-
post 'vote', to: :vote, controller: 'items'
50-
end
51-
resource :discussion, only: [:create, :destroy, :update] do
52-
post 'transitions', controller: 'transitions'
53-
end
44+
resources :retros, only: [:index, :create, :show, :update] do
45+
resources :archives, only: [:index, :show]
46+
resources :settings, only: [:index]
47+
resources :action_items, only: [:create, :destroy, :update]
48+
resources :items, only: [:create, :update, :destroy] do
49+
patch 'done', to: :done, controller: 'items'
50+
post 'vote', to: :vote, controller: 'items'
51+
end
52+
resource :discussion, only: [:create, :destroy, :update] do
53+
post 'transitions', controller: 'transitions'
54+
end
5455

55-
resources :sessions, only: [:new, :create]
56+
resources :sessions, only: [:new, :create]
57+
end
5658
end
59+
60+
# pushstate routing
61+
get '/' => 'static#home', as: 'home', constraints: { format: :html }
62+
get '*url' => 'static#home', constraints: { format: :html }
5763
end

api/spec/requests/oauth_sessions_request_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
end
4848

4949
it 'returns user details' do
50-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
50+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
5151

5252
expect(response.status).to eq(200)
5353

@@ -76,7 +76,7 @@
7676
end
7777

7878
it 'returns user details' do
79-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
79+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
8080

8181
expect(response.status).to eq(200)
8282

@@ -85,7 +85,7 @@
8585
end
8686

8787
it 'returns a token' do
88-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
88+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
8989

9090
expect(response.status).to eq(200)
9191

@@ -107,7 +107,7 @@
107107
end
108108

109109
it 'responds with an expiring token' do
110-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
110+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
111111

112112
data = JSON.parse(response.body)
113113
jwt = JWT.decode(data['auth_token'], nil, false)
@@ -129,7 +129,7 @@
129129
end
130130

131131
it 'returns 404' do
132-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
132+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
133133

134134
expect(response.status).to eq(404)
135135
end
@@ -143,7 +143,7 @@
143143
end
144144

145145
it 'returns 500' do
146-
post '/sessions', params: { access_token: 'invalid-access-token' }, as: :json
146+
post '/api/sessions', params: { access_token: 'invalid-access-token' }, as: :json
147147

148148
expect(response.status).to eq(500)
149149
end
@@ -155,7 +155,7 @@
155155
.with('the-access-token')
156156
.and_raise(GoogleClient::InvalidUserDomain.new)
157157

158-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
158+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
159159
expect(response).to be_forbidden
160160
end
161161

@@ -168,7 +168,7 @@
168168

169169
expect(GOOGLE_CLIENT).to receive(:get_user!).with('the-access-token').and_return(google_user_data)
170170

171-
post '/sessions', params: { access_token: 'the-access-token' }, as: :json
171+
post '/api/sessions', params: { access_token: 'the-access-token' }, as: :json
172172
expect(response).to be_not_found
173173
end
174174
end

0 commit comments

Comments
 (0)