Technology4 min read

Refactoring The_Internet: Deploying the web app to Render

By · Published by Everything Blog

In short

### Briefing We are currently deploying the web app "The-Internet" to Render, a cloud platform as a service (PaaS) that allows developers to host websites, web applications, databases, and background services without having to manage underlying server infrastructure. It allows developers to easily set up and manage their projects without the hassle of managing server infrastructure. The platform is particularly useful for developers who want to focus on their code and not worry about the underlying infrastructure.

Key points

  • ### Briefing We are currently deploying the web app "The-Internet" to Render, a cloud pl…: ### Briefing We are currently deploying the web app "The-Internet" to Render, a cloud platform as a service (PaaS) that allows developers to host websites, web applications, databases, and background services without having to manage under
  • It allows developers to easily set up and manage their projects without the hassle of man…: It allows developers to easily set up and manage their projects without the hassle of managing server infrastructure.
  • The platform is particularly useful for developers who want to focus on their code and no…: The platform is particularly useful for developers who want to focus on their code and not worry about the underlying infrastructure.

We are well on our way to place a copy of my favorite test site, The-Internet, onto its new home on Render.com, a place where developers can deploy web apps using their free tier, much like Heroku in its heyday. Sure, web apps that live on the free tier of Render takes a minute or so to spin up, but, hey, you get what you pay for!

With our last blog post, we:

- Examined using Google AI the Gemfile of the original The-Internet, a Ruby project at https://github.com/saucelabs/the-internet, hosting on the failing site, https://the-internet.herokuapp.com/

- Created a new copy of the web app onto my GitHub site, forking the original repo

- Updated the Ruby architecture of the web app per Google AI's findings.

- Tested the web app could be deployed locally and pushed the changes to my GitHub site: https://github.com/tjmaher/the-internet

With this blog post, we will create a new account on Render, a new project, and set up a new home for The-Internet.

What the Heck is Render?

Render is a cloud platform as a service (PaaS) that allows developers to host websites, web applications, databases, and background services without having to manage underlying server infrastructure.

According to StartupIntros.com / Render:

- Read: Founder Interviews: Anurag Goel of Render (2019): https://hackernoon.com/founder-interviews-anurag-goel-of-render-cfcad8e92dae

How to Set Up Render

According to https://render.com/docs/your-first-deploy

- Select "Sign Up For Render" to go to https://dashboard.render.com/register

- Select "GitHub" and log into your GitHub account, sharing your information with Render.

- Select to host a web service.

- Connect to my GitHub code repositories

- Chose to install Render on tmaher/the-internet

Render pre-filled:

- The name of the project to "the-internet", the language to be "Docker", the branch to be "main".

- Chose the free tier, using .01 CPUs and 512 MB RAM. Free instances spin down after a period of inactivity.

- Render had me create for my project a Render.yaml file:

services:

- type: web

name: the-internet-modern

env: ruby

buildCommand: |

bundle config set --local without "development test"

bundle install

startCommand: bundle exec rackup -p $PORT -o 0.0.0.0

envVars:

- key: RUBY_VERSION

value: "3.4.2"

- Selected "Deploy web service".

- Since the-internet must be pretty common, it appended a four letter suffix to the url: https://the-internet-8uaj.onrender.com/

... And it failed. It showed the message: HOST NOT PERMITTED

How To Fix Sinatra Problems

Why did going to https://the-internet-8uaj.onrender.com/ show: Host not permitted?

When I asked Google AI, it said that:

"Starting with version 4.1.0, Sinatra introduced strict, built-in security middleware called Rack::Protection::HostAuthorization. By default, this middleware blocks HTTP requests unless the accessing URL matches an allowed list (typically defaulting only to localhost). When Render routes traffic to your app through the-internet-8uaj.onrender.com, Sinatra flags it as an unrecognized hostname and throws a 403 Forbidden response with the body text 'Host not permitted'"

As a solution, it had me add to the existing server.rb file:

server.rb

class Protected < Sinatra::Base

set :host_authorization, permitted_hosts: []

register Sinatra::Flash

. . .

. . .

class Public < Sinatra::Base

set :host_authorization, permitted_hosts: []

helpers Sinatra::Cookies

As soon as I made the changes, and pushed them to GitHub. They automatically deployed to the website.. which took a while to load up after going to https://the-internet-8uaj.onrender.com/.

After this brief interlude. going to https://the-internet-8uaj.onrender.com/login we see ... a Login Page!

So now, when I run a Playwright test framework, and I have it hooked up to test versus The-Internet / Login, I just need to remember to swap out the URL and add some time for the page to load.

Feel free to use the website if you would like!

-T.J. Maher

Software Engineer in Test

BlueSky | YouTube | LinkedIn | Articles

No comments:

Post a Comment

Original source: www.tjmaher.com

Technology