<?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: Mehmet Kırkoca</title>
    <description>The latest articles on DEV Community by Mehmet Kırkoca (@mehmetkirkoca).</description>
    <link>https://dev.to/mehmetkirkoca</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%2F243174%2Fee74d121-8e44-4477-a2ef-31628c74d351.jpeg</url>
      <title>DEV Community: Mehmet Kırkoca</title>
      <link>https://dev.to/mehmetkirkoca</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mehmetkirkoca"/>
    <language>en</language>
    <item>
      <title>Unit Testing with Jest and Rewire in JavaScript</title>
      <dc:creator>Mehmet Kırkoca</dc:creator>
      <pubDate>Sun, 17 Sep 2023 07:53:39 +0000</pubDate>
      <link>https://dev.to/mehmetkirkoca/unit-testing-with-jest-and-rewire-in-javascript-15o4</link>
      <guid>https://dev.to/mehmetkirkoca/unit-testing-with-jest-and-rewire-in-javascript-15o4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Unit testing is a crucial aspect of modern software development, ensuring code reliability and correctness. In this guide, we will explore unit testing using Jest, a powerful testing framework, and introduce the rewire module to enhance your testing capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Rewire&lt;/strong&gt;?&lt;br&gt;
When unit testing JavaScript code, it’s essential to isolate the functions or modules you’re testing to ensure that you’re only evaluating the specific functionality you’re interested in. However, JavaScript’s module system can sometimes make this challenging, as it doesn’t provide a straightforward way to access and manipulate the internal state of a module.&lt;/p&gt;

&lt;p&gt;This is where the rewire module comes into play. Rewire is a tool that allows you to access and modify private variables and functions within a module. It effectively "rewires" the module, giving you greater control and visibility into its internals during testing, all while preserving encapsulation in your production code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Rewire with Jest&lt;/strong&gt;&lt;br&gt;
Let’s dive into practical examples of how to use Jest and Rewire together for effective unit testing. These test cases are from my open-source project, the social media manager.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const rewire = require('rewire');
const formatter = rewire('../index');

describe('formatForTwitter', () =&amp;gt; {
  it('should format a message for Twitter', async () =&amp;gt; {
    const message = 'Hello, Twitter!';
    const formatForTwitter = formatter.__get__('formatForTwitter');
    const result = await formatForTwitter(message);
    expect(result).toBe('message formatted for twitter: Hello, Twitter!');
  });
});

describe('formatForLinkedIn', () =&amp;gt; {
  it('should format a message for LinkedIn', async () =&amp;gt; {
    const message = 'Hello, LinkedIn!';
    const formatForLinkedIn = formatter.__get__('formatForLinkedIn');

    const result = await formatForLinkedIn(message);
    expect(result).toBe('message formatted for linkedin: Hello, LinkedIn!');
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this context, we seamlessly integrate Jest and Rewire to access and test the internal functions within the index.js file. This approach enables us to comprehensively test private functions while preserving encapsulation in the production code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of This Approach&lt;/strong&gt;&lt;br&gt;
Combining Jest and Rewire offers several advantages for unit testing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Isolation and Focus:&lt;/strong&gt; You can concentrate on testing specific functions without exposing them in your production code, preserving encapsulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simplicity and Clarity:&lt;/strong&gt; The testing process becomes simpler, as you can easily access and modify private variables and functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Confidence in Functionality:&lt;/strong&gt; By testing internal functions in isolation, you can gain confidence in their correctness and expected behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Maintainable Tests:&lt;/strong&gt; Tests remain robust even if you refactor your code or change the module’s internal structure, as long as the public API remains consistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Mastering unit testing with Jest and Rewire in JavaScript empowers you to ensure the reliability and correctness of your code. By combining these powerful tools, you can confidently test private functions and variables while maintaining the integrity of your production code. With this approach, you’ll be better equipped to deliver high-quality, error-free JavaScript applications.&lt;/p&gt;

</description>
      <category>unittest</category>
      <category>jest</category>
      <category>rewire</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Nginx Configuration Setting up a Reverse Proxy</title>
      <dc:creator>Mehmet Kırkoca</dc:creator>
      <pubDate>Sun, 17 Sep 2023 07:49:49 +0000</pubDate>
      <link>https://dev.to/mehmetkirkoca/nginx-configuration-setting-up-a-reverse-proxy-2g5m</link>
      <guid>https://dev.to/mehmetkirkoca/nginx-configuration-setting-up-a-reverse-proxy-2g5m</guid>
      <description>&lt;p&gt;In this article, As some of you may know, Nginx is a web server and reverse proxy server capable of handling incoming HTTP requests and distributing them to multiple back-end servers. I will show you how I set up a reverse proxy using the &lt;a href="https://github.com/mehmetkirkoca/social-media-manager/blob/main/nginx.conf"&gt;nginx.conf&lt;/a&gt; file for the &lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social media manager project&lt;/a&gt; I am working on. We have four locations: two of them belong to the UI service, one is for the socket.io service, and the last one is for API calls.&lt;/p&gt;

&lt;p&gt;This is the real-world scenario I’m utilizing for my social media manager project with this configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;events {}
http {
  server {
    listen 80;
    server_name localhost;
    location / {
        proxy_pass http://ui:5173;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    location /ws {
        proxy_pass http://ui:5173;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    location /socket.io/ {
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_pass  http://socket:8084/socket.io/;
    }
    location /api/ {
      rewrite ^/api/(.*) /$1 break;
      proxy_pass http://gateway:8084;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Basic Nginx Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An Nginx configuration is organized into blocks: http, server, and location.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Starting an HTTP Block:&lt;/strong&gt;&lt;br&gt;
http { … } block defines the start of an HTTP server configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Defining a Server Block:&lt;/strong&gt;&lt;br&gt;
The ‘server { … }’ block is your command center, providing configuration settings for a specific server. The ‘listen’ directive is your server’s attentive ear, indicating which port to tune into — usually, it’s 80, the standard for HTTP communication. But what about the ‘server_name’? It’s your online identity, specifying your domain name, which in our case is simply, “localhost”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Location Blocks:&lt;/strong&gt;&lt;br&gt;
location blocks determine how Nginx handles requests based on their URL path. / location handles requests to the root (“/”) and proxies them to a front-end named “ui” on port 5173.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proxying Requests:&lt;/strong&gt;&lt;br&gt;
proxy_pass directive forwards requests to the specified webservice.&lt;/p&gt;

&lt;p&gt;proxy_set_header is an essential component of setting up a reverse proxy in Nginx configuration. When you use this directive, you’re essentially defining HTTP headers to the request sent to the proxied servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Specific Functions of proxy_set_header&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Host:&lt;/strong&gt; The host is one of the header fields in an HTTP request, and this represents the host and port number of the server to which the request is being sent. In the context of proxy_set_header, it refers to the host for which the request should appear to be intended.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;X-Real-IP:&lt;/strong&gt; This, on the other hand, is used to give the server information about the client’s IP address. Typically, when there’s a proxy in the mix, the client’s IP address can get lost. However, proxy_set_header can send this in a header, so the server knows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Upgrade:&lt;/strong&gt; The connection can then “upgrade” from HTTP to a different protocol such as WebSocket. This is triggered by the client sending an Upgrade request header in its HTTP request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connection:&lt;/strong&gt; Ensures the connection is maintained during the upgrade&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using proxy_set_header&lt;/strong&gt;&lt;br&gt;
Here’s an example of how you might use the proxy_set_header directive:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;proxy_set_header Host $http_host;&lt;br&gt;
proxy_set_header X-Real-IP $remote_addr;&lt;br&gt;
proxy_set_header Upgrade $http_upgrade;&lt;br&gt;
proxy_set_header Connection 'upgrade';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These settings aid in maintaining the original client’s address even when requests are being made through a proxy server, as the HTTP header would carry the IP address in the form of the X-real-IP. Plus, it helps set up a seamless WebSocket connection.&lt;/p&gt;

&lt;p&gt;In summary, proxy_set_header serves a critical role in setting up a reverse proxy configuration with Nginx. It not only maintains the request’s integrity but also enables advanced features like WebSocket support.&lt;/p&gt;

&lt;p&gt;sets HTTP headers for proxying, such as Host, X-Real-IP, and headers needed for WebSocket support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling WebSocket Requests:&lt;/strong&gt;&lt;br&gt;
WebSocket connections are enabled using proxy_http_version, Upgrade, and Connection headers. The second location /ws block handles WebSocket requests and forwards them similarly to the “ui” backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Specific Routes:&lt;/strong&gt;&lt;br&gt;
The third location /socket.io/ block forwards requests to a different backend service on port 8084, intended for WebSocket communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rewriting URL Paths:&lt;/strong&gt;&lt;br&gt;
The fourth location /api/ block rewrites URL paths, removing the “/api” prefix, and proxies requests to a “gateway” backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
If you’re orchestrating multiple services, Nginx as a reverse proxy simplifies communication. Try it and supercharge your project!&lt;/p&gt;

&lt;p&gt;What do you think about using Nginx as a reverse proxy? Share your thoughts and experiences in the comments below!&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>reverseproxy</category>
      <category>microservices</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Open Source Social Media Management</title>
      <dc:creator>Mehmet Kırkoca</dc:creator>
      <pubDate>Sun, 17 Sep 2023 07:41:36 +0000</pubDate>
      <link>https://dev.to/mehmetkirkoca/open-source-social-media-management-11mk</link>
      <guid>https://dev.to/mehmetkirkoca/open-source-social-media-management-11mk</guid>
      <description>&lt;p&gt;In this article, I will provide you with information about a &lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social media management&lt;/a&gt; app. The idea for creating this app originated from my experience of opening multiple social media accounts. Unfortunately, they remained inactive because managing them all simultaneously was challenging. To solve this problem, an idea struck me: I can generate content and then share it across all my social media accounts. However, I soon realized that each social media platform has different requirements, such as Twitter’s character limit. That’s when the idea for such an application emerged, and I began researching.&lt;/p&gt;

&lt;p&gt;While similar applications were already available on the internet, most of them were paid. However, I noticed that there was no free and open-source &lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social media management&lt;/a&gt; application that I could run on my own server, so I decided to take action to address this issue.&lt;/p&gt;

&lt;p&gt;My goal is to develop a high-quality product and make it available to everyone for free as open source software. Of course, I have other motivations, such as enhancing my own experience and creating an application I can use as a reference.&lt;/p&gt;

&lt;p&gt;If you also struggle with managing multiple social media platforms, setting alarms to remind you to post on time, dealing with the complexities of formatting each post according to different requirements, and want to handle interactions with your audience on multiple platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technologies Used&lt;/strong&gt;&lt;br&gt;
‘&lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social-media-manager&lt;/a&gt;’ utilizes a powerful technology stack to enhance the user experience:&lt;br&gt;
Node.js: Provides high performance and reliability to support the front-end and microservices.&lt;br&gt;
Vue.js: Offers a dynamic, user-friendly frontend for an intuitive and visually appealing interface.&lt;br&gt;
Tailwind CSS: Utilizes Tailwind CSS to create an elegant and functional design.&lt;br&gt;
Nginx: Efficiently routes and deploys the application by using Nginx as the preferred reverse proxy for the gateway API and sockets.&lt;br&gt;
Docker: Facilitates the deployment of applications by using container technology like Docker for scalability.&lt;br&gt;
Fastify: Uses Fastify, a high-performance web framework, to support fast interactions.&lt;br&gt;
RabbitMQ: Ensures seamless operation by using a communication system like RabbitMQ to facilitate communication between microservices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tr1ScLXI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhzed50p9fswk7b7zdq9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tr1ScLXI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhzed50p9fswk7b7zdq9.png" alt="Image description" width="797" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features It Will Provide&lt;/strong&gt;&lt;br&gt;
Automatic Post Formatting: This application automatically formats your posts to meet the requirements of each platform using artificial intelligence, eliminating the need for manual formatting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages for Users&lt;/strong&gt;&lt;br&gt;
Efficiency: Saves time by automating post formatting and automatically reposting content across multiple platforms.&lt;br&gt;
Centralized Management: Provides easy access to all your social media accounts through a single user-friendly interface.&lt;br&gt;
Scheduled Posts: Allows you to schedule and publish posts at ideal times, maximizing your reach and engagement without considering your audience’s time zones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation and Usage&lt;/strong&gt;&lt;br&gt;
Getting started with ‘&lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social-media-manager&lt;/a&gt;’ is straightforward:&lt;br&gt;
Make sure Docker is installed on your system.&lt;br&gt;
Clone the project from GitHub.&lt;br&gt;
Run the ‘docker-compose up’ command to install the necessary containers.&lt;br&gt;
That’s it!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Join Us!&lt;/strong&gt;&lt;br&gt;
Our vibrant community eagerly awaits your participation:&lt;br&gt;
Show your support by starring the project. Fork the project, get involved deeply, and actively contribute. We welcome your contributions, whether you’ve found a bug or have groundbreaking feature ideas. Share your ideas and suggestions by opening discussions. Engage in constructive conversations and help shape the future of social media management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Future Plans&lt;/strong&gt;&lt;br&gt;
As ‘&lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social-media-manager&lt;/a&gt;’ evolves, we commit to working more systematically with contributors and community members. Together, we will learn, adapt, and improve the project based on user feedback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In conclusion, ‘&lt;a href="https://github.com/mehmetkirkoca/social-media-manager"&gt;social-media-manager&lt;/a&gt;’ may be the answer to your social media management challenges. With open-source spirit, and commitment to the future, it can assist individuals and businesses in achieving success in the digital world.&lt;/p&gt;

</description>
      <category>socialmediamanagement</category>
      <category>onlinepresence</category>
      <category>opensource</category>
      <category>microservices</category>
    </item>
  </channel>
</rss>
