Skip to content

Commit e087837

Browse files
authored
fix: update appengine samples to allow local dev testing (#1528)
1 parent b519b0b commit e087837

File tree

20 files changed

+87
-12
lines changed

20 files changed

+87
-12
lines changed

appengine/analytics/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
require "sinatra"
1717
require "net/http"
1818

19+
# [END gae_flex_analytics_track_event]
20+
# Allows all hosts in development
21+
configure :development do
22+
set :host_authorization, { permitted_hosts: [] }
23+
end
24+
25+
# [START gae_flex_analytics_track_event]
1926
# The following environment variable is set by app.yaml when running on GAE,
2027
# but will need to be manually set when running locally. See README.md.
2128
GA_TRACKING_ID = ENV["GA_TRACKING_ID"]

appengine/cloud-tasks/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
require "sinatra"
1919
require "json"
2020

21+
# [END cloud_tasks_appengine_quickstart]
22+
# Allows all hosts in development
23+
configure :development do
24+
set :host_authorization, { permitted_hosts: [] }
25+
end
26+
27+
# [START cloud_tasks_appengine_quickstart]
2128
get "/" do
2229
# Basic index to verify app is serving
2330
"Hello World!"

appengine/datastore/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
require "sinatra"
1818
require "google/cloud/datastore"
1919

20+
# [END gae_flex_datastore_app]
21+
# Allows all hosts in development
22+
configure :development do
23+
set :host_authorization, { permitted_hosts: [] }
24+
end
25+
26+
# [START gae_flex_datastore_app]
2027
get "/" do
2128
datastore = Google::Cloud::Datastore.new
2229

appengine/hello_world/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
# [START gae_flex_quickstart]
1616
require "sinatra"
1717

18+
# [END gae_flex_quickstart]
19+
# Allows all hosts in development
20+
configure :development do
21+
set :host_authorization, { permitted_hosts: [] }
22+
end
23+
24+
# [START gae_flex_quickstart]
1825
get "/" do
1926
"Hello world!"
2027
end

appengine/metadata_server/Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
source "https://rubygems.org"
1616

17-
gem "sinatra", "~> 3.2"
17+
gem "puma"
18+
gem "rackup", "~> 1.0"
19+
gem "sinatra"
1820

1921
group :test do
2022
gem "faraday"

appengine/metadata_server/Gemfile.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ GEM
1111
ruby2_keywords (~> 0.0.1)
1212
net-http (0.4.1)
1313
uri
14+
nio4r (2.7.4)
15+
puma (6.6.0)
16+
nio4r (~> 2.0)
1417
rack (2.2.8.1)
1518
rack-protection (3.2.0)
1619
base64 (>= 0.1.0)
1720
rack (~> 2.2, >= 2.2.4)
21+
rackup (1.0.1)
22+
rack (< 3)
23+
webrick
1824
rspec (3.13.0)
1925
rspec-core (~> 3.13.0)
2026
rspec-expectations (~> 3.13.0)
@@ -38,15 +44,18 @@ GEM
3844
tilt (~> 2.0)
3945
tilt (2.3.0)
4046
uri (0.13.0)
47+
webrick (1.9.1)
4148

4249
PLATFORMS
4350
ruby
4451

4552
DEPENDENCIES
4653
faraday
54+
puma
55+
rackup (~> 1.0)
4756
rspec
4857
rspec_junit_formatter
49-
sinatra (~> 3.2)
58+
sinatra
5059

5160
BUNDLED WITH
5261
2.4.22

appengine/metadata_server/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
require "sinatra"
1717
require "net/http"
1818

19+
# [END gae_flex_metadata]
20+
# Allows all hosts in development
21+
configure :development do
22+
set :host_authorization, { permitted_hosts: [] }
23+
end
24+
25+
# [START gae_flex_metadata]
1926
get "/" do
2027
uri = URI.parse(
2128
"http://metadata.google.internal/computeMetadata/v1" +

appengine/metadata_server/app.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@
1515
runtime: ruby
1616
env: flex
1717
entrypoint: bundle exec ruby app.rb
18+
19+
runtime_config:
20+
operating_system: "ubuntu22"

appengine/pubsub/app.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
pubsub = Google::Cloud::Pubsub.new
2323

24+
# Allows all hosts in development
25+
configure :development do
26+
set :host_authorization, { permitted_hosts: [] }
27+
end
28+
2429
# [START gae_flex_pubsub_env]
2530
topic = pubsub.topic ENV["PUBSUB_TOPIC"]
2631
PUBSUB_VERIFICATION_TOKEN = ENV["PUBSUB_VERIFICATION_TOKEN"]

appengine/standard-analytics/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# [START gae_standard_analytics_env_variables]
16-
runtime: ruby30
16+
runtime: ruby33
1717
entrypoint: bundle exec ruby app.rb
1818

1919
env_variables:

appengine/standard-cloud-tasks/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: ruby30
15+
runtime: ruby33
1616
entrypoint: bundle exec ruby app.rb

appengine/standard-datastore/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: ruby30
15+
runtime: ruby33
1616
entrypoint: bundle exec ruby app.rb

appengine/standard-hello_configs/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# [START gae_standard_configs_app_yaml]
16-
runtime: ruby30
16+
runtime: ruby33
1717

1818
entrypoint: bundle exec puma -C ./puma.rb
1919

appengine/standard-hello_world/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# [START gae_standard_quickstart_yaml]
16-
runtime: ruby30
16+
runtime: ruby33
1717
entrypoint: bundle exec ruby app.rb
1818
instance_class: F2
1919
# [END gae_standard_quickstart_yaml]

appengine/standard-metadata-server/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
require "sinatra"
1717
require "net/http"
1818

19+
# [END gae_standard_metadata]
20+
# Allows all hosts in development
21+
configure :development do
22+
set :host_authorization, { permitted_hosts: [] }
23+
end
24+
25+
# [START gae_standard_metadata]
1926
get "/" do
2027
uri = URI.parse(
2128
"http://metadata.google.internal/computeMetadata/v1" +

appengine/standard-metadata-server/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: ruby30
15+
runtime: ruby33
1616
entrypoint: bundle exec ruby app.rb

appengine/standard-storage/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# [START gae_standard_storage_yaml]
16-
runtime: ruby30
16+
runtime: ruby33
1717
entrypoint: bundle exec ruby app.rb
1818

1919
env_variables:

appengine/storage/app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
require "sinatra"
1717
require "google/cloud/storage"
1818

19+
# [END gae_flex_storage_app]
20+
# Allows all hosts in development
21+
configure :development do
22+
set :host_authorization, { permitted_hosts: [] }
23+
end
24+
25+
# [START gae_flex_storage_app]
1926
storage = Google::Cloud::Storage.new
2027
bucket = storage.bucket ENV["GOOGLE_CLOUD_STORAGE_BUCKET"]
2128

appengine/storage/spec/storage_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
describe "Cloud Storage", type: :feature do
2121
before do
22-
Capybara.current_driver = :cuprite
22+
Capybara.register_driver :cuprite do |app|
23+
Capybara::Cuprite::Driver.new(app, browser_options: {'no-sandbox': nil})
24+
end
2325
end
2426
it "can upload and get public URL of uploaded file" do
2527
Capybara.app = Sinatra::Application
@@ -31,7 +33,7 @@
3133

3234
uploaded_file_public_url = page.find("body").text
3335

34-
visit uploaded_file_public_url
35-
expect(page).to have_content "This is the content of the test-upload.txt file"
36+
page = Net::HTTP.get_response(URI(uploaded_file_public_url))
37+
expect(page.body).to include "This is the content of the test-upload.txt file"
3638
end
3739
end

appengine/twilio/app.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
require "sinatra"
1616
require "twilio-ruby"
1717

18+
# Allows all hosts in development
19+
configure :development do
20+
set :host_authorization, { permitted_hosts: [] }
21+
end
22+
1823
TWILIO_ACCOUNT_SID = ENV["TWILIO_ACCOUNT_SID"]
1924
TWILIO_AUTH_TOKEN = ENV["TWILIO_AUTH_TOKEN"]
2025
TWILIO_NUMBER = ENV["TWILIO_NUMBER"]

0 commit comments

Comments
 (0)