<?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: Roberto Conte Rosito</title>
    <description>The latest articles on DEV Community by Roberto Conte Rosito (@robyconte).</description>
    <link>https://dev.to/robyconte</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%2F341224%2F00055de3-5715-4fae-875e-6006de070680.jpeg</url>
      <title>DEV Community: Roberto Conte Rosito</title>
      <link>https://dev.to/robyconte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/robyconte"/>
    <language>en</language>
    <item>
      <title>Spring Boot and MongoDB Aggregation Issues - What a pain!</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Sat, 18 May 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/spring-boot-and-mongodb-aggregation-issues-what-a-pain-e8</link>
      <guid>https://dev.to/robyconte/spring-boot-and-mongodb-aggregation-issues-what-a-pain-e8</guid>
      <description>&lt;p&gt;&lt;em&gt;Welcome back to my dev notes!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I guys, too much time is passed since my last post, but I'm back with a new one. Today I want to talk about a problem I faced with Spring Boot and MongoDB aggregations.&lt;/p&gt;

&lt;p&gt;This problem is really annoying, and I spent a lot of time trying to solve it. The problem is that sometimes the aggregation doesn't work as expected, and you don't know why. The real problem is that I've created a suite of tests that cover all the possible cases, but sometimes the aggregation &lt;em&gt;still&lt;/em&gt; doesn't work as expected.&lt;/p&gt;

&lt;p&gt;I was in trouble but after hours of debugging I remembered that I faced the same problem in the past and it took me a lot of time to solve it too (which is way I've turned on my blog to write about it).&lt;br&gt;
But let's stop talking, and get to the point!&lt;/p&gt;

&lt;p&gt;Suppose you have something like that in your spring boot application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;aggregation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newAggregation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Criteria&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"value"&lt;/span&gt;&lt;span class="o"&gt;)),&lt;/span&gt;
  &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;as&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"count"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"count"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"field"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;previousOperation&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mongoTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;aggregate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aggregation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"collection"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;YourClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getMappedResults&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes, and I still don't know why, this aggregation doesn't work as expected. The problem is that the &lt;code&gt;result&lt;/code&gt; list is empty. You can try to change the aggregation in many ways, and I can guarantee that I've tried every kind of operation, but the problem is still there, waiting for you to solve it.&lt;/p&gt;

&lt;p&gt;You can try to get the result of aggregation in debug mode, copy it in to your MongoDB Compass instance, try to execute it &lt;strong&gt;and guess what?&lt;/strong&gt; It works! &lt;strong&gt;But in your application no, it doesn't work.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The solution is quite simple, but it took me a lot of time to find it. The problem is that the &lt;code&gt;mongoTemplate&lt;/code&gt; is not able to work with the name of the collection as a string (I suppose it's a bug but I have to investigate, for now it's my reponsability to share what I know with you).&lt;/p&gt;

&lt;p&gt;This line of code is wrong (or to be more precise, &lt;strong&gt;sometimes&lt;/strong&gt; is wrong):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mongoTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;aggregate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aggregation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"collection"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;YourClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getMappedResults&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to be sure that everything is executed as mongodb do, you have to pass your class instance instead of the collection name, is my habit to do thinks like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;collectionName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mongoTemaplte&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCollectionName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;YourClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Wrong!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do it like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mongoTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;aggregate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aggregation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;YourClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;YourClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getMappedResults&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This signature is similar to the previous one, but the difference is that you pass the class instance instead of the collection name. This way the &lt;code&gt;mongoTemplate&lt;/code&gt; is able to work with the aggregation as expected.&lt;/p&gt;

&lt;p&gt;Believe me, I had nightmares with this problem, but now I'm happy to share the solution with you.&lt;br&gt;
If you know more about this problem, please let me know, I'm really interested in understanding why this happens.&lt;/p&gt;

&lt;p&gt;For now, as always, happy coding!&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>mongodb</category>
      <category>aggregation</category>
    </item>
    <item>
      <title>Setup Google Cloud Storage Service Account</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Tue, 08 Aug 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/setup-google-cloud-storage-service-account-4bca</link>
      <guid>https://dev.to/robyconte/setup-google-cloud-storage-service-account-4bca</guid>
      <description>&lt;p&gt;I was in trouble with this for a while so I decided to write down this guide to help me in the future and maybe it will help you too.&lt;/p&gt;

&lt;p&gt;The goal is quite simple: I’ve to create a google service account needed by my pipeline to publish docker images to the Google Cloud Container Registry.&lt;/p&gt;

&lt;p&gt;This account &lt;strong&gt;must&lt;/strong&gt; have the following permissions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App Engine Admin&lt;/li&gt;
&lt;li&gt;Cloud API Gateway Service Agent&lt;/li&gt;
&lt;li&gt;Cloud Deploy Admin&lt;/li&gt;
&lt;li&gt;Cloud Infrastructure Manager Admin&lt;/li&gt;
&lt;li&gt;Container Registry Service Agent&lt;/li&gt;
&lt;li&gt;Environment and Storage Object Administrator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sorry guys but without these permissions I was not able to make it work! &lt;strong&gt;Do you know which one is not needed? Please let me know!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>gcp</category>
      <category>serviceaccount</category>
      <category>containerregistry</category>
    </item>
    <item>
      <title>Setup Spring Boot with JPA and MySQL</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Mon, 20 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/setup-spring-boot-with-jpa-and-mysql-4l62</link>
      <guid>https://dev.to/robyconte/setup-spring-boot-with-jpa-and-mysql-4l62</guid>
      <description>&lt;p&gt;&lt;em&gt;Welcome back to my dev notes!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Few things that I’ve to remember next time I need to setup a Spring Boot project with JPA and MySQL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the following dependencies to your &lt;code&gt;pom.xml&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;spring-boot-starter-data-jpa&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;mysql&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;mysql-connector-java&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the following properties to your &lt;code&gt;application.properties&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create your model using &lt;code&gt;@Entity&lt;/code&gt; and &lt;code&gt;@Id&lt;/code&gt; annotations:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entity
public class User {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;
 private String name;
 private String email;
 private String password;
 // getters and setters
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create your repository extending &lt;code&gt;JpaRepository&lt;/code&gt; adding &lt;code&gt;@Repository&lt;/code&gt; annotation:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Repository
public interface UserRepository extends JpaRepository&amp;lt;User, Long&amp;gt; {}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are ready to &lt;code&gt;@Autowired&lt;/code&gt; your repository and use it in your services/controllers.&lt;/p&gt;

&lt;p&gt;That’s all for today, see you next time!&lt;/p&gt;

</description>
      <category>spring</category>
      <category>jpa</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Setup HTTPS with Nginx and Docker</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Tue, 28 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/setup-https-with-nginx-and-docker-1e19</link>
      <guid>https://dev.to/robyconte/setup-https-with-nginx-and-docker-1e19</guid>
      <description>&lt;p&gt;&lt;em&gt;Welcome back to my dev notes!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today I was in trouble for a while because I wanted to setup HTTPS with Nginx and Docker and I completely forgot how to do it. So I decided to write down this guide to help me in the future and maybe it will help you too.&lt;/p&gt;

&lt;p&gt;I have a Docker container running a PHP application served by Nginx and I wanted to setup HTTPS with a self-signed certificate because I need to test some OAuth flows.&lt;/p&gt;

&lt;p&gt;Follow these steps to setup HTTPS with Nginx and Docker:&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a self-signed certificate
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl x509 -outform pem -in localhost.crt -out localhost.pem

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Edit nginx configuration
&lt;/h1&gt;

&lt;p&gt;Please take attention to the &lt;code&gt;ssl_certificate&lt;/code&gt; and &lt;code&gt;ssl_certificate_key&lt;/code&gt; files paths.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
 listen 443 ssl;
 server_name localhost;
 ssl_certificate /etc/nginx/ssl/localhost.crt;
 ssl_certificate_key /etc/nginx/ssl/localhost.key;
 ...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Restart docker
&lt;/h1&gt;

&lt;p&gt;If you are a perfectionist like me you can also add the certificate to your system keychain to avoid browser warnings. Using Mac OS you can do it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain localhost.crt

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>nginx</category>
      <category>https</category>
    </item>
    <item>
      <title>How to use useRef with React Hook Form</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Mon, 30 Jan 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/how-to-use-useref-with-react-hook-form-55c5</link>
      <guid>https://dev.to/robyconte/how-to-use-useref-with-react-hook-form-55c5</guid>
      <description>&lt;p&gt;&lt;em&gt;Welcome back to my dev notes!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today I was in trouble for a while because I wanted to use a ref inside a React-Hook-Form form with an input of type &lt;code&gt;file&lt;/code&gt; and I couldn’t do it.&lt;/p&gt;

&lt;p&gt;The problem was quite simple, suppose you have a form like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { register } = useFormContext();
const fileInputRef = useRef(null);
const handleClick = useCallback(() =&amp;gt; {
 fileInputRef.current.click();
}, [fileInputRef]);
return (
 &amp;lt;&amp;gt;
   &amp;lt;input type="file" ref={fileInputRef} {...register("file")} /&amp;gt;
   &amp;lt;button onClick={handleClick}&amp;gt;Upload&amp;lt;/button&amp;gt;
 &amp;lt;/&amp;gt;
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And guess what? It didn’t work. The &lt;code&gt;fileInputRef&lt;/code&gt; was &lt;code&gt;null&lt;/code&gt; inside the &lt;code&gt;handleClick&lt;/code&gt; function and I couldn’t understand why. After googling for a while I found the solution: you have to use the &lt;code&gt;register&lt;/code&gt; method in a different way to make it work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { register } = useFormContext();
const { ref, ...inputProps } = register("file");
const fileInputRef = useRef(null);
const handleClick = useCallback(() =&amp;gt; {
 fileInputRef.current.click();
}, [fileInputRef]);

return (
 &amp;lt;&amp;gt;
   &amp;lt;input
     type="file"
     ref={(e) =&amp;gt; {
       fileInputRef.current = e;
       ref(e);
     }}
     {...inputProps}
   /&amp;gt;
   &amp;lt;button onClick={handleClick}&amp;gt;Upload&amp;lt;/button&amp;gt;
 &amp;lt;/&amp;gt;
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this will help you if you are in trouble with refs and React Hook Form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notes&lt;/strong&gt; : this is a dev note, not a tutorial. If you want to learn more about React Hook Form, check out the &lt;a href="https://react-hook-form.com/" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>offers</category>
    </item>
    <item>
      <title>How to use setValue with React Hook Form</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Wed, 18 Jan 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/how-to-use-setvalue-with-react-hook-form-4dp</link>
      <guid>https://dev.to/robyconte/how-to-use-setvalue-with-react-hook-form-4dp</guid>
      <description>&lt;p&gt;My dev notes about how to set value with React Hook Form. Following the &lt;a href="https://react-hook-form.com/api/useform/setvalue" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;you can set a value with React Hook Form using the &lt;code&gt;setValue&lt;/code&gt; method to change it programmatically like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { setValue } = useForm();
...
setValue("firstName", "bill");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;But this is wrong!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have to use the &lt;code&gt;setValue&lt;/code&gt; method to change the value of a field programmatically, &lt;strong&gt;but only&lt;/strong&gt; using the &lt;code&gt;useFormContext&lt;/code&gt; hook instead of the &lt;code&gt;useForm&lt;/code&gt; hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { setValue } = useFormContext();
...
// Somewhere inside the form
setValue("firstName", "bill");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt; the first one is used during initialization of the form, the second one is used inside the form.&lt;/p&gt;

</description>
      <category>reacthookform</category>
      <category>react</category>
      <category>setvalue</category>
    </item>
    <item>
      <title>Publish superset dashboard on React/NextJS apps</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Mon, 02 Jan 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/publish-superset-dashboard-on-reactnextjs-apps-2569</link>
      <guid>https://dev.to/robyconte/publish-superset-dashboard-on-reactnextjs-apps-2569</guid>
      <description>&lt;p&gt;Superset is a great tool to create and publish different kind of dashboards. In this post I will show you how to publish and embed a superset dashboard on a React/NextJS app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Superset
&lt;/h2&gt;

&lt;p&gt;Superset expose everything required to publish data but you need to configure few things before start (this guide assumes you have already installed superset).&lt;/p&gt;

&lt;p&gt;Open &lt;code&gt;config.py&lt;/code&gt; and add these changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;search &lt;code&gt;ENABLE_CORS&lt;/code&gt; and change it to &lt;code&gt;True&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;replace &lt;code&gt;CORS_OPTIONS&lt;/code&gt; (should be located after &lt;code&gt;ENABLE_CORS&lt;/code&gt;) with this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CORS_OPTIONS = {
 'supports_credentials': True,
 'allow_headers': ['*'],
 'resources':['*'],
 'origins': ['*']
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;origins&lt;/code&gt; property should be configured based on your requirements, in development mode you can use &lt;code&gt;*&lt;/code&gt; to allow all origins but in production you should specify the domain of your app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;search &lt;code&gt;EMBEDDED_SUPERSET&lt;/code&gt; and change it to &lt;code&gt;True&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;search &lt;code&gt;PUBLIC_ROLE_LIKE&lt;/code&gt; and change it to &lt;code&gt;Public&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;search &lt;code&gt;GUEST_TOKEN_JWT_SECRET&lt;/code&gt; and change it to random string to enforce security.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Restart your superset instance to activate the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure public role
&lt;/h2&gt;

&lt;p&gt;Public role needs to be updated with the following permissions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;can read on Chart&lt;/li&gt;
&lt;li&gt;can read on Dataset&lt;/li&gt;
&lt;li&gt;can read on Dashboard&lt;/li&gt;
&lt;li&gt;can read on Database&lt;/li&gt;
&lt;li&gt;can write on DashboardFilterStateRestApi&lt;/li&gt;
&lt;li&gt;can read on DashboardfilterStateRestApi&lt;/li&gt;
&lt;li&gt;can dashboard on Superset&lt;/li&gt;
&lt;li&gt;can explore json on Superset&lt;/li&gt;
&lt;li&gt;can grant guest token on SecurityRestApi&lt;/li&gt;
&lt;li&gt;all database access on all_database_access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without these permissions you will not be able to publish your dashboard ( you will get a 403 error when you will try to access the dashboard).&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure guest account
&lt;/h2&gt;

&lt;p&gt;Now you are ready to configure guest account that will be used to access dashboard without username and password. Go in Settings/List Users and create a new user, the most important part is the &lt;strong&gt;Roles&lt;/strong&gt; field, you have to select &lt;strong&gt;Public&lt;/strong&gt; and &lt;strong&gt;Gamma&lt;/strong&gt; roles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup your React/NextJS app
&lt;/h2&gt;

&lt;p&gt;Superset comes out with a default NPM plugin, @superset-ui/embedded-sdk, that helps in the process of publication. On top of this I’ve created another wrapper that uses React component to display data and take care of DOM initialization.&lt;/p&gt;

&lt;p&gt;Install the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -S superset-dashboard-sdk

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To publish a dashboard you need to create a new data provider, this is a class that will be used to fetch data from superset. The data provider is a class that extends &lt;code&gt;DefaultDataProvider&lt;/code&gt; and it’s used to fetch data from superset. The &lt;code&gt;DefaultDataProvider&lt;/code&gt; class is a wrapper of &lt;code&gt;SupersetClient&lt;/code&gt; class that comes out with &lt;code&gt;@superset-ui/embedded-sdk&lt;/code&gt; package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// dataProvider.js
import { DefaultDataProvider } from 'superset-dashboard-sdk';
const dp = new DefaultDataProvider("http://localhost:8088", {
 username: "guest"
 password: "guest"
});
export default dp;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can use the data provider to publish your dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js
import { Dashboard } from "superset-dashboard-sdk";
import dataProvider from "./dataProvider";
const App = () =&amp;gt; &amp;lt;Dashboard dataProvider={dp} id="&amp;lt;id of dashboard&amp;gt;" /&amp;gt;;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To obtain a valid dashboard id you can open superset, navigate to dashboard and click on “…” (three dots) on the top right corner. Then click on &lt;strong&gt;Enable Embedding&lt;/strong&gt; to generate and see the uuid associated with selected dashboard. Also remember to add &lt;strong&gt;Guest&lt;/strong&gt; account to the list of owners of the dashboard to avoid problems with permissions.&lt;/p&gt;

&lt;p&gt;Hope this helps you too, feel free to write a comment if you have any question or suggestion.&lt;/p&gt;

</description>
      <category>superset</category>
      <category>react</category>
      <category>nextjs</category>
      <category>embedded</category>
    </item>
    <item>
      <title>Deploy a .net app on a local kind cluster</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Tue, 20 Dec 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/deploy-a-net-app-on-a-local-kind-cluster-3ed2</link>
      <guid>https://dev.to/robyconte/deploy-a-net-app-on-a-local-kind-cluster-3ed2</guid>
      <description>&lt;p&gt;This guide will help you throught the process of deploying a .Net app on a local &lt;a href="https://kind.sigs.k8s.io/" rel="noopener noreferrer"&gt;kind&lt;/a&gt; cluster. I was just curious to see how it works and I decided to write an article about it (after studying the correct way to do it).&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This guide assumes you have alreay installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/tasks/tools/" rel="noopener noreferrer"&gt;kubectl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kind.sigs.k8s.io/docs/user/quick-start/#installation" rel="noopener noreferrer"&gt;kind&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.github.io/ingress-nginx/deploy/#docker-for-mac" rel="noopener noreferrer"&gt;ingress-nginx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can follow the guide &lt;a href="https://dev.to/robyconte/deploy-a-local-kind-cluster"&gt;Deploy a local kind cluster&lt;/a&gt; to install all the prerequisites or you can just install kind and ingress-nginx fastes way possible by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind create cluster --config kind/config.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you are ready to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a .Net app
&lt;/h2&gt;

&lt;p&gt;I’ve created a github repo with a simple .Net app that will be deployed on the kind cluster. You can find it &lt;a href="https://github.com/RoBYCoNTe/hello-world-k8s-net" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The app is a simple web api that returns a string or interact with files (to test my understanding of volumes).&lt;/p&gt;

&lt;p&gt;You can try it locally by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/RoBYCoNTe/hello-world-k8s-net.git
cd hello-world-k8s-net
dotnet restore
dotnet run

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The app will be available on port 5000 and you can test it by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl http://localhost:5000/v1
curl http://localhost:5000/v1/files/append?line=Hello

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a Dockerfile
&lt;/h2&gt;

&lt;p&gt;Using kubernetes we can deploy a containerized application. To do that we need to create a Dockerfile that will be used to build the image that will be deployed on the cluster.&lt;/p&gt;

&lt;p&gt;Inside the repo you can find a Dockerfile already prepared. You can find it &lt;a href="https://github.com/RoBYCoNTe/hello-world-k8s-net/blob/main/Dockerfile" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before building the image you have to login into your docker hub account. To do that run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker login

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then build the image by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t &amp;lt;your-docker-hub-username&amp;gt;/hello-world-k8s-net:latest .

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Push the image to Docker Hub
&lt;/h2&gt;

&lt;p&gt;To push the image to Docker Hub run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push &amp;lt;your-docker-hub-username&amp;gt;/hello-world-k8s-net:latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;Now that we have the image ready we can create a deployment that will deploy the image on the cluster. Before creating the deployment you have to instruct your cluster to pull the image from Docker Hub. To do that run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create secret docker-registry dockerhub --docker-server=https://index.docker.io/v1/ --docker-username=&amp;lt;your-docker-hub-username&amp;gt; --docker-password=&amp;lt;your-docker-hub-password&amp;gt; --docker-email=&amp;lt;your-docker-hub-email&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With previous command we have created a secret that will be used by the deployment to pull the image from Docker Hub (you cannot pull an image from Docker Hub without a secret). For more information about how to configure a secret to pull an image from Docker Hub you can read &lt;a href="https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/" rel="noopener noreferrer"&gt;this&lt;/a&gt; article.&lt;/p&gt;

&lt;p&gt;The deployment is defined in the file &lt;a href="https://github.com/RoBYCoNTe/hello-world-k8s-net/blob/main/k8s/deployment.yml" rel="noopener noreferrer"&gt;deployment.yaml&lt;/a&gt;. You can find it in the repo.&lt;/p&gt;

&lt;p&gt;Before creating the deployment we have to create PVCs that will be used by the deployment to store data. To do that run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f k8s/pv.yaml
kubectl apply -f k8s/pvc.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without the PVCs the deployment will fail because it will not be able to store data.&lt;/p&gt;

&lt;p&gt;Now we can create the deployment by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f k8s/deployment.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt; to change the image name in the deployment file with your own image name.&lt;/p&gt;

&lt;p&gt;Now we can create service and ingress to expose the app to the outside world. To do that run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt; to change the host in the ingress file with your own host and to add the host to your &lt;code&gt;/etc/hosts&lt;/code&gt; file (if you are using linux) or to your &lt;code&gt;hosts&lt;/code&gt; file (if you are using windows).&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the app
&lt;/h2&gt;

&lt;p&gt;To test the app run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -H "Host: hello-world-k8s-net.local" http://localhost/v1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the classic “Hello World!” message.&lt;/p&gt;

&lt;p&gt;I was just curious to see how volumes work on a local kind cluster. To test it run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -H "Host: hello-world-k8s-net.local" http://localhost/v1/files/append?line=Hello

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you execute the previous command multiple time you will see that the file is updated with the new line (it is returned by the api). Furthermore if you delete the pod or restart the cluster the file will still be there.&lt;/p&gt;

&lt;p&gt;For example, if we redeploy the app by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rollout restart deployment hello-world-k8s-net

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Executing the curl command again will return the same result!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This guide was just a way to test how volumes work on a local kind cluster. I’ve learned that volumes are not deleted when you delete a pod or when you restart the cluster. Furthermore I’ve learned that you can use a secret to pull an image from Docker Hub. I’ve to says that first tries were not successful because I was using a wrong secret, missing to install ingress-nginx, missing to create PVC and so on. I’ve learned that you have to read the error messages and try to understand what is going on. Most of the time the error messages are pretty clear and you can understand what is going on, if not you can always ask for help on the internet.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this guide and I hope you learned something new. If you have any question or suggestion please leave a comment below.&lt;/p&gt;

</description>
      <category>kind</category>
      <category>cluster</category>
      <category>kubernetes</category>
      <category>k8s</category>
    </item>
    <item>
      <title>Deploy a local kind cluster</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Mon, 19 Dec 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/deploy-a-local-kind-cluster-3blc</link>
      <guid>https://dev.to/robyconte/deploy-a-local-kind-cluster-3blc</guid>
      <description>&lt;p&gt;This guide will help you throught the process of deploying a local &lt;a href="https://kind.sigs.k8s.io/" rel="noopener noreferrer"&gt;kind&lt;/a&gt; cluster.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Kind is a tool for running local Kubernetes clusters using Docker container “nodes”. Kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This guide assumes you have alreay installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/tasks/tools/" rel="noopener noreferrer"&gt;kubectl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kind.sigs.k8s.io/docs/user/quick-start/#installation" rel="noopener noreferrer"&gt;kind&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a cluster
&lt;/h2&gt;

&lt;p&gt;Create a kind config file called &lt;code&gt;kind-config.yaml&lt;/code&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
 - role: control-plane
 kubeadmConfigPatches:
 - |
 kind: InitConfiguration
 nodeRegistration:
 kubeletExtraArgs:
 node-labels: "ingress-ready=true"
 extraPortMappings:
 - containerPort: 80
 hostPort: 80
 protocol: TCP
 - containerPort: 443
 hostPort: 443
 protocol: TCP

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create the cluster using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind create cluster --config kind-config.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The configured cluster is ready to accept requests on port 80 and 443.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install ingress controller
&lt;/h2&gt;

&lt;p&gt;By default k8s does not have an ingress controller installed. To install the ingress controller run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the &lt;strong&gt;nginx&lt;/strong&gt; ingress controller in the cluster (the most used ingress controller right now, but you can install many other, the only thing you have to do is to change the &lt;code&gt;ingressClassName&lt;/code&gt; in your ingress resources).&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the cluster
&lt;/h2&gt;

&lt;p&gt;To test the cluster you can create a simple deployment and a service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl run hello \
 --expose \
 --image nginxdemos/hello:plain-text \
 --port 80

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a file called &lt;code&gt;ingress.yaml&lt;/code&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: hello
spec:
 rules:
 - host: hello.robertoconterosito.it
 http:
 paths:
 - pathType: ImplementationSpecific
 backend:
 service:
 name: hello
 port:
 number: 80

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then apply the ingress resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f ingress.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can test the ingress resource using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -H "Host: hello.robertoconterosito.it" localhost

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>kind</category>
      <category>cluster</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Bootstrap-Italia Design Kit with NextJS app</title>
      <dc:creator>Roberto Conte Rosito</dc:creator>
      <pubDate>Sat, 05 Nov 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/robyconte/bootstrap-italia-design-kit-with-nextjs-app-1ebh</link>
      <guid>https://dev.to/robyconte/bootstrap-italia-design-kit-with-nextjs-app-1ebh</guid>
      <description>&lt;p&gt;This guide will help you throught the process of configuring &lt;a href="https://github.com/italia/bootstrap-italia/" rel="noopener noreferrer"&gt;bootstrap-italia&lt;/a&gt; in your NextJS app&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;During this process you will probably face errors related to unrecognized static assets (csv, svg, fonts etc.) that can be solved quite simply in NextJS app using specific webpack config and NextJS components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Install Bootstrap-Italia
&lt;/h2&gt;

&lt;p&gt;First of all, install bootstrap-italia in your NextJS app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -S bootstrap-italia

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Webpack
&lt;/h2&gt;

&lt;p&gt;Now you have to install a plugin, &lt;code&gt;copy-webpack-plugin&lt;/code&gt;, required to move static assets from the &lt;code&gt;node_modules&lt;/code&gt; folder (boostrap-italia) in to the project build folder using webpack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i --save-dev copy-webpack-plugin

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install a new plugin that we have to use inside our next.config.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const CopyPlugin = require("copy-webpack-plugin");
const path = require("path");
// Prepare from/to
const from = "node_modules/bootstrap-italia/dist/";
const to = path.join(__dirname, "./public/bootstrap-italia/dist");
const nextConfig = {
 webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) =&amp;gt; {
 config.plugins.push(
 new CopyPlugin({
 patterns: [{ from, to }],
 })
 );
 return config;
 },
};
module.exports = nextConfig;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next time you run your app you will see a new folder, inside public, called bootstrap-italia with all assets required to work with NextJS app.&lt;/p&gt;

&lt;p&gt;You can choose to copy these files statically executing a Copy/Paste operation but I prefer this solution to automatically include updates when necessary (when the bootstrap-italia package will be updated).&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure _app.js
&lt;/h2&gt;

&lt;p&gt;Import basic CSS globally in _app.js adding this code on top of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "bootstrap-italia/dist/css/bootstrap-italia.min.css";

const App = ({ Component, pageProps }) =&amp;gt; {
 return &amp;lt;Component {...pageProps} /&amp;gt;;
};
export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Script TAG
&lt;/h2&gt;

&lt;p&gt;Supposing you have a common set of elements necessary to display your page and there exists a file called Layout where all the UX logic starts, you have to add a link to the javascript bundle required by bootstrap-italia to work correctly with you project, like in the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Header from "./Header";
import React from "react";
import Script from "next/script";
const Layout = ({ children }) =&amp;gt; (
 &amp;lt;div&amp;gt;
 &amp;lt;Header /&amp;gt;
 {children}
 &amp;lt;Script src="bootstrap-italia/dist/js/bootstrap-italia.bundle.min.js" /&amp;gt;
 &amp;lt;/div&amp;gt;
);
export default Layout;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are ready to see a running NextJS app with bootstrap-italia UX.&lt;/p&gt;

</description>
      <category>bootstrap</category>
      <category>designkit</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
