<?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: Mohamed Jbeli</title>
    <description>The latest articles on DEV Community by Mohamed Jbeli (@unlocomqx).</description>
    <link>https://dev.to/unlocomqx</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%2F191669%2F19047469-f983-4cf0-af26-c0ad4048d87e.png</url>
      <title>DEV Community: Mohamed Jbeli</title>
      <link>https://dev.to/unlocomqx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/unlocomqx"/>
    <language>en</language>
    <item>
      <title>A much better DX for Shopify apps</title>
      <dc:creator>Mohamed Jbeli</dc:creator>
      <pubDate>Sun, 06 Jun 2021 17:54:35 +0000</pubDate>
      <link>https://dev.to/unlocomqx/a-much-better-dx-for-shopify-apps-38ln</link>
      <guid>https://dev.to/unlocomqx/a-much-better-dx-for-shopify-apps-38ln</guid>
      <description>&lt;p&gt;When creating a shopify app, you often have to use ngrok because the shopify embed requires https. But using ngrok when you just got used to the speed of vitejs will feel very slow. and will give you a bad developer experience.&lt;/p&gt;

&lt;p&gt;Fortunately, there is a better way.&lt;/p&gt;

&lt;p&gt;The solution is to enable https on localhost by ourselves using mkcert.&lt;/p&gt;

&lt;p&gt;This method will use docker but it's not completely necessary as you can still install nginx or apache directly on your OS and the method would still work.&lt;/p&gt;

&lt;h2&gt;
  
  
  mkcert: generate the ssl certificates
&lt;/h2&gt;

&lt;p&gt;To start, we install &lt;a href="https://github.com/FiloSottile/mkcert#installation" rel="noopener noreferrer"&gt;mkcert&lt;/a&gt;, then we install a CA (Certificate authority) using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkcert &lt;span class="nt"&gt;-install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we generate our self-signed certificate like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkcert local.dev localhost 127.0.0.1 ::1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can replace &lt;code&gt;local.dev&lt;/code&gt; with any domain of your choice&lt;/p&gt;

&lt;h2&gt;
  
  
  Editing the hosts file
&lt;/h2&gt;

&lt;p&gt;Finally, add this line to your hosts file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1 local.dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the certificates
&lt;/h2&gt;

&lt;p&gt;The next step depends on what you use to develop your app, but the tool you use certainly supports configuring a certificate that will be used when serving the app in dev mode, here are some examples&lt;br&gt;
&lt;a href="https://webpack.js.org/configuration/dev-server/#devserverhttps" rel="noopener noreferrer"&gt;WebPack Dev Server&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vitejs.dev/config/#server-https" rel="noopener noreferrer"&gt;ViteJs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.thesslstore.com/knowledgebase/ssl-install/apache-openssl-installation/" rel="noopener noreferrer"&gt;Apache&lt;/a&gt;&lt;br&gt;
&lt;a href="http://nginx.org/en/docs/http/configuring_https_servers.html" rel="noopener noreferrer"&gt;Nginx&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating a reverse proxy (it's easier than it sounds)
&lt;/h2&gt;

&lt;p&gt;Since you are probably serving your app over a specific port that is different than port 80, then shopify embed won't accept that, i.e. something like this &lt;a href="https://local.dev:8081" rel="noopener noreferrer"&gt;https://local.dev:8081&lt;/a&gt; won't be accepted.&lt;/p&gt;

&lt;p&gt;There is probably a simpler solution but the method that worked for me was to create a reverse proxy using apache or nginx.&lt;/p&gt;

&lt;p&gt;Here's a working solution that uses docker and nginx&lt;br&gt;
&lt;a href="https://github.com/unlocomqx/nginx-docker-ssl-proxy" rel="noopener noreferrer"&gt;https://github.com/unlocomqx/nginx-docker-ssl-proxy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, I can access SvelteKit using &lt;a href="https://local.dev" rel="noopener noreferrer"&gt;https://local.dev&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.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%2F8wlvu6vgdmni1qo3hy4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F8wlvu6vgdmni1qo3hy4e.png" alt="Dev app served through https"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you use apache, here's a config that you can add to your virtual hosts file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&amp;lt;&lt;span class="n"&gt;VirtualHost&lt;/span&gt; *:&lt;span class="m"&gt;80&lt;/span&gt;&amp;gt;
    &lt;span class="n"&gt;ProxyPreserveHost&lt;/span&gt; &lt;span class="n"&gt;On&lt;/span&gt;

    &lt;span class="n"&gt;ProxyPass&lt;/span&gt; / &lt;span class="s2"&gt;"http://host.docker.internal:8081/"&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;=&lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;ProxyPassReverse&lt;/span&gt; / &lt;span class="s2"&gt;"http://host.docker.internal:8081/"&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;=&lt;span class="m"&gt;0&lt;/span&gt;

    &lt;span class="n"&gt;ServerName&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;.&lt;span class="n"&gt;dev&lt;/span&gt;
&amp;lt;/&lt;span class="n"&gt;VirtualHost&lt;/span&gt;&amp;gt;

&amp;lt;&lt;span class="n"&gt;VirtualHost&lt;/span&gt; *:&lt;span class="m"&gt;443&lt;/span&gt;&amp;gt;
    &lt;span class="n"&gt;ProxyPreserveHost&lt;/span&gt; &lt;span class="n"&gt;On&lt;/span&gt;

    &lt;span class="n"&gt;SSLEngine&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;

    &lt;span class="n"&gt;SSLCertificateFile&lt;/span&gt;      /&lt;span class="n"&gt;etc&lt;/span&gt;/&lt;span class="n"&gt;ssl&lt;/span&gt;/&lt;span class="n"&gt;certs&lt;/span&gt;/&lt;span class="n"&gt;cert&lt;/span&gt;.&lt;span class="n"&gt;pem&lt;/span&gt;
    &lt;span class="n"&gt;SSLCertificateKeyFile&lt;/span&gt;   /&lt;span class="n"&gt;etc&lt;/span&gt;/&lt;span class="n"&gt;ssl&lt;/span&gt;/&lt;span class="n"&gt;certs&lt;/span&gt;/&lt;span class="n"&gt;key&lt;/span&gt;.&lt;span class="n"&gt;pem&lt;/span&gt;

    &lt;span class="n"&gt;ProxyPass&lt;/span&gt; / &lt;span class="s2"&gt;"http://host.docker.internal:8081/"&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;=&lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;ProxyPassReverse&lt;/span&gt; / &lt;span class="s2"&gt;"http://host.docker.internal:8081/"&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;=&lt;span class="m"&gt;0&lt;/span&gt;

    &lt;span class="n"&gt;ServerName&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;.&lt;span class="n"&gt;dev&lt;/span&gt;
&amp;lt;/&lt;span class="n"&gt;VirtualHost&lt;/span&gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feel free to share other tools configs in the comments&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconfiguring our Shopify app
&lt;/h2&gt;

&lt;p&gt;To tell shopify to load the app through local.dev, we need to change our app url in the partner dashboard&lt;br&gt;
&lt;a href="https://media.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%2Fov6i7wssg9qn0hgxcftr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fov6i7wssg9qn0hgxcftr.png" alt="Partner Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fosk3o1t00hceteudfepp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fosk3o1t00hceteudfepp.jpg" alt="App URLs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also don't forget to edit your &lt;code&gt;.env&lt;/code&gt; file by setting the host var&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HOST=https://local.dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can access your start your app using this url&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://local.dev/?shop=shopname.myshopify.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can install it to your test shop from the partner dashboard&lt;/p&gt;

&lt;p&gt;If you would like to use SvelteKit to develop your Shopify app, check this template&lt;br&gt;
&lt;a href="https://github.com/unlocomqx/shopify-app-sveltekit" rel="noopener noreferrer"&gt;https://github.com/unlocomqx/shopify-app-sveltekit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's how the end result looks&lt;br&gt;
&lt;a href="https://media.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%2Fxjkxku4i28mzdnbwg82v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fxjkxku4i28mzdnbwg82v.png" alt="Shopify Embed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison with ngrok
&lt;/h2&gt;

&lt;p&gt;I compared the SvelteKit demo app load and found a big difference&lt;/p&gt;

&lt;p&gt;ngrok load time: 21s (but maybe I have a slow internet 12Down/1Up)&lt;br&gt;
ngrok vite hmr: 450ms&lt;/p&gt;

&lt;p&gt;localhost load time: under 1s (as you might expect)&lt;br&gt;
localhost vite hmr: 30ms&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally
&lt;/h2&gt;

&lt;p&gt;I hope this give you a better developer experience and make developing shopify apps a lot more enjoyable&lt;/p&gt;

</description>
      <category>shopify</category>
    </item>
    <item>
      <title>Faster dev server with(out) xDebug </title>
      <dc:creator>Mohamed Jbeli</dc:creator>
      <pubDate>Tue, 17 Nov 2020 09:33:28 +0000</pubDate>
      <link>https://dev.to/unlocomqx/faster-dev-server-with-xdebug-3833</link>
      <guid>https://dev.to/unlocomqx/faster-dev-server-with-xdebug-3833</guid>
      <description>&lt;p&gt;It has been said before, to make xDebug faster, just disable it.&lt;br&gt;
But one still needs xDebug for how helpful it is!&lt;br&gt;
Well, there is a good solution which is to only enable xDebug when we intend to debug the request.&lt;/p&gt;

&lt;p&gt;The idea is to create two php containers (&lt;code&gt;php&lt;/code&gt; and &lt;code&gt;php_xdebug&lt;/code&gt;) and enable xDebug on only one of these two containers.&lt;br&gt;
Then we can instruct &lt;code&gt;apache&lt;/code&gt; to use the &lt;code&gt;php_xdebug&lt;/code&gt; container only when a certain cookie is set.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php&lt;/code&gt; container&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fj7cxZQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/AYQnxe7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fj7cxZQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/AYQnxe7.png" alt="php container info"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php_xdebug&lt;/code&gt; container&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GpTKUhT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Q6JU7eg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GpTKUhT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Q6JU7eg.png" alt="php_xdebug container info"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;apache&lt;/code&gt; config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;lt;If&lt;/span&gt; &lt;span class="err"&gt;"%{HTTP_COOKIE}&lt;/span&gt; &lt;span class="err"&gt;=~&lt;/span&gt; &lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="py"&gt;XDEBUG_SESSION&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;PHPSTORM/"&amp;gt;&lt;/span&gt;
  &lt;span class="err"&gt;SetHandler&lt;/span&gt; &lt;span class="err"&gt;"proxy:fcgi://php_xdebug:9000"&lt;/span&gt;
&lt;span class="err"&gt;&amp;lt;/If&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt;&amp;lt;Else&amp;gt;&lt;/span&gt;
  &lt;span class="err"&gt;SetHandler&lt;/span&gt; &lt;span class="err"&gt;"proxy:fcgi://php:9000"&lt;/span&gt;
&lt;span class="err"&gt;&amp;lt;/Else&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in this case, we only use php_xdebug when the &lt;code&gt;XDEBUG_SESSION&lt;/code&gt; cookie is set to &lt;code&gt;PHPSTORM&lt;/code&gt;.&lt;br&gt;
The &lt;code&gt;PHPSTORM&lt;/code&gt; value itself can be changed in the env file and in the xDebug helper browser extension.&lt;/p&gt;

&lt;p&gt;The rest is very simple, we just need to configure xDebug to always start remote debugging when it's invoked.&lt;br&gt;
The &lt;code&gt;profiler&lt;/code&gt; and &lt;code&gt;log&lt;/code&gt; output will be sent to a &lt;code&gt;/tmp&lt;/code&gt; folder inside the server root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;zend_extension&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;xdebug.so&lt;/span&gt;
&lt;span class="nn"&gt;[xdebug]&lt;/span&gt;
&lt;span class="py"&gt;xdebug.remote_autostart&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;xdebug.remote_enable&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;xdebug.remote_handler&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;dbgp&lt;/span&gt;
&lt;span class="py"&gt;xdebug.remote_connect_back&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;xdebug.profiler_enable_trigger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;xdebug.profiler_output_dir&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/var/www/html/tmp&lt;/span&gt;
&lt;span class="py"&gt;xdebug.idekey&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;${XDEBUG_COOKIE_VALUE}&lt;/span&gt;
&lt;span class="py"&gt;xdebug.remote_log&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/var/www/html/tmp/xdebug.log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the docker-compose file in this github repo&lt;br&gt;
&lt;a href="https://github.com/unlocomqx/conditional-xdebug-fpm-docker"&gt;https://github.com/unlocomqx/conditional-xdebug-fpm-docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After cloning the repo, you can rename the file &lt;code&gt;sample.env&lt;/code&gt; to &lt;code&gt;.env&lt;/code&gt; and change &lt;code&gt;DOCUMENT_ROOT&lt;/code&gt;, &lt;code&gt;MYSQL_DATA_DIR&lt;/code&gt; and &lt;code&gt;XDEBUG_COOKIE_VALUE&lt;/code&gt; if necessary.&lt;/p&gt;

&lt;p&gt;This solution was totally inspired by this blog post &lt;a href="https://jtreminio.com/blog/developing-at-full-speed-with-xdebug/"&gt;https://jtreminio.com/blog/developing-at-full-speed-with-xdebug/&lt;/a&gt; &lt;/p&gt;

</description>
      <category>docker</category>
      <category>php</category>
    </item>
  </channel>
</rss>
