<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucho Quiruga</title>
    <description>The latest articles on DEV Community by Lucho Quiruga (@luchoquiru).</description>
    <link>https://dev.to/luchoquiru</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F988996%2Fe0aa18e5-ddd2-4c41-974d-75f5b018faa1.jpeg</url>
      <title>DEV Community: Lucho Quiruga</title>
      <link>https://dev.to/luchoquiru</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luchoquiru"/>
    <language>en</language>
    <item>
      <title>Deploy a Laravel Breeze app in Railway loading styles correctly</title>
      <dc:creator>Lucho Quiruga</dc:creator>
      <pubDate>Tue, 20 Dec 2022 14:40:12 +0000</pubDate>
      <link>https://dev.to/luchoquiru/deploy-a-laravel-breeze-app-in-railway-loading-styles-correctly-3e5o</link>
      <guid>https://dev.to/luchoquiru/deploy-a-laravel-breeze-app-in-railway-loading-styles-correctly-3e5o</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Create Laravel app + Laravel Breeze&lt;/li&gt;
&lt;li&gt;Deploying in Railway&lt;/li&gt;
&lt;li&gt;Problem: Blocked resources&lt;/li&gt;
&lt;li&gt;Mixed Content&lt;/li&gt;
&lt;li&gt;Solution&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In some cases the deployment of a Laravel Breeze app to some PAAS, in this case Railway, can have some style problems in the application view. This problem is related to the concept of mixed content, which we will see later on.&lt;/p&gt;

&lt;p&gt;We will see why this problem is generated in production and how to solve it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: It can be useful to understand the cause and solution of the problem, because this problem can occur also with applications developed with other technology, or deployed on other platforms.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Create Laravel app + Laravel Breeze
&lt;/h2&gt;

&lt;p&gt;Now let's create a Laravel application and then include Laravel Breeze. The next steps follow the guides of the official documentation of Laravel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project laravel/laravel example-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan breeze:install

php artisan migrate
npm install
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In 127.0.0.1 the application looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxw1k40saggohndv7pc47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxw1k40saggohndv7pc47.png" alt="Laravel app styles working correctly" width="501" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Deploying in Railway
&lt;/h1&gt;

&lt;p&gt;&lt;a href="//railway.app"&gt;Railway&lt;/a&gt; is an infrastructure platform where you can provision infrastructure, and allows us to deploy our applications and databases for free (with limitations).&lt;/p&gt;

&lt;p&gt;Let's see how to make the deploy for our example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a repository on GitHub and push the app into it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmqdh0vsw1n0p74kdl3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmqdh0vsw1n0p74kdl3p.png" alt="Image description" width="437" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We configure the repository to our local project and push the app, following GitHub steps:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "# LaravelExample" &amp;gt;&amp;gt; README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/LuchoQuiru/LaravelExample.git
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In &lt;a href="//railway.app"&gt;Railway&lt;/a&gt; we login with GitHub account.
Then we create a new project by pressing the button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx2fcjxxwanpijj001ci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx2fcjxxwanpijj001ci.png" alt="Image description" width="232" height="60"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we configure the repository to the project in railway:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Press &lt;strong&gt;"+ new"&lt;/strong&gt; button and select "GitHub repo"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbrxqmwxdvf5u7zmj0cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbrxqmwxdvf5u7zmj0cw.png" alt="Image description" width="98" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hv72j0vouljqwylx9v2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hv72j0vouljqwylx9v2.png" alt="Image description" width="463" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F00uz4i6gytv3i3fkzda9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F00uz4i6gytv3i3fkzda9.png" alt="Image description" width="462" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we give access to the repository, and save&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3gnll48ir9kh4sm5062.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3gnll48ir9kh4sm5062.png" alt="Image description" width="533" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now can select the app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wl8nuiwtoitsm05y8wz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wl8nuiwtoitsm05y8wz.png" alt="Image description" width="470" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now set up a database, in this case Postgres&lt;br&gt;
Again press &lt;strong&gt;+ new&lt;/strong&gt; button -&amp;gt; &lt;strong&gt;Database&lt;/strong&gt; -&amp;gt; &lt;strong&gt;add Postgres&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgqyb2ncu9hyg5m452mz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgqyb2ncu9hyg5m452mz.png" alt="Image description" width="473" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A postgres database was created, from which we obtain the following variables for connecting to the database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgx6fnbtw0pd58sgcw0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgx6fnbtw0pd58sgcw0e.png" alt="Image description" width="393" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then, we set the environment variables for the application by pressing the raw editor button, , and copying the contents of the application .env file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwfndbapnsiukkr2chop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwfndbapnsiukkr2chop.png" alt="Image description" width="745" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjd6syhcai8cqdssf0bpv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjd6syhcai8cqdssf0bpv.png" alt="Image description" width="590" height="554"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the configuration tab, in the Deploy section we add the following start command:
composer install &amp;amp;&amp;amp; php artisan breeze:install &amp;amp;&amp;amp; php artisan migrate --force &amp;amp;&amp;amp; npm install &amp;amp;&amp;amp; php artisan serve --host=0.0.0.0 --port=$PORT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54wgtsjitk5w6ao2boif.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54wgtsjitk5w6ao2boif.png" alt="Image description" width="740" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far the deployment of the application should be done. But it looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvq724wf3x58k1o3r62yg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvq724wf3x58k1o3r62yg.png" alt="Laravel app styles broken" width="639" height="476"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Problem: Blocked resources
&lt;/h1&gt;

&lt;p&gt;The problem is that the request to obtain the style files for the application is blocked, and the view is altered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj7makfn5007xhsiobhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj7makfn5007xhsiobhu.png" alt="Image description" width="375" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The message that we obtain in console is:&lt;br&gt;
&lt;strong&gt;Mixed Content:&lt;/strong&gt; The page at &lt;a href="https://production.up.railway.app/login" rel="noopener noreferrer"&gt;https://production.up.railway.app/login&lt;/a&gt; was loaded over HTTPS, but requested an insecure stylesheet &lt;a href="http://production.up.railway.app/build/assets/app.e87db8d1.css" rel="noopener noreferrer"&gt;http://production.up.railway.app/build/assets/app.e87db8d1.css&lt;/a&gt;. &lt;strong&gt;This request has been blocked; the content must be served over HTTPS.&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Mixed Content
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;What is Mixed Content&lt;/strong&gt;&lt;br&gt;
Mixed content occurs when initial HTML is loaded over a secure HTTPS connection, but other resources (such as images, videos, stylesheets, scripts) are loaded over an insecure HTTP connection.&lt;/p&gt;

&lt;p&gt;In our Laravel example the stylesheets are locked because of this.&lt;/p&gt;

&lt;p&gt;Requesting sub-resources using the insecure HTTP protocol weakens the security of the entire site, as these requests are vulnerable to en-route attacks also known as &lt;a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" rel="noopener noreferrer"&gt;man-in-the-middle&lt;/a&gt;, where an attacker eavesdrops on a network connection and views or modifies the communication between two parties.&lt;/p&gt;

&lt;p&gt;As a consequence and for security reasons, the browser blocks mixed content. &lt;/p&gt;
&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;One way to avoid mixed content is to force the laravel application to require resources over a secure https connection.&lt;/p&gt;

&lt;p&gt;In laravel we can solve it from the &lt;a href="https://laravel.com/docs/9.x/providers" rel="noopener noreferrer"&gt;Service Provider&lt;/a&gt;, &lt;strong&gt;inside the boot() method&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Service providers are the central place of all Laravel application bootstrapping.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then we tell Laravel to force all routes to be https if we are in the production context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(config('app.env') === 'production') {
            \URL::forceScheme('https');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way we eliminate mixed content as all resources are now requested over a secure https connection.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Now the browser allows us to obtain all the resources and we can see the application and its styles working correctly. &lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
