<?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: Dan George</title>
    <description>The latest articles on DEV Community by Dan George (@dangeorge35).</description>
    <link>https://dev.to/dangeorge35</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%2F1101094%2F14963e75-4726-4bbe-8215-b2c7ca5ce4b7.jpeg</url>
      <title>DEV Community: Dan George</title>
      <link>https://dev.to/dangeorge35</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dangeorge35"/>
    <language>en</language>
    <item>
      <title>Leveraging .htaccess on for Efficient API Routing in Main and Stage Environments on apache</title>
      <dc:creator>Dan George</dc:creator>
      <pubDate>Sun, 28 Apr 2024 05:40:53 +0000</pubDate>
      <link>https://dev.to/dangeorge35/leveraging-htaccess-on-for-efficient-api-routing-in-main-and-stage-environments-on-apache-4k67</link>
      <guid>https://dev.to/dangeorge35/leveraging-htaccess-on-for-efficient-api-routing-in-main-and-stage-environments-on-apache-4k67</guid>
      <description>&lt;p&gt;In web development, efficient routing of API requests is crucial for seamless communication between frontend and backend systems. Whether you're deploying your application to a main production environment or a staging environment for testing and validation, having a reliable routing mechanism is essential. In this blog post, we'll explore how to utilize the power of .htaccess files to streamline API routing in both main and stage environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is .htaccess?&lt;/strong&gt;&lt;br&gt;
.htaccess is a configuration file used by Apache web servers to control various aspects of website functionality, including URL redirection, access control, and custom error pages. It provides a flexible way to manipulate incoming requests and direct them to specific locations within the web server's filesystem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficient API Routing with .htaccess&lt;/strong&gt;&lt;br&gt;
The provided .htaccess configuration snippet offers a comprehensive solution for routing API requests in both main and stage environments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;IfModule mod_rewrite.c&amp;gt;
    RewriteEngine On
    RewriteBase /

    # Redirect all requests to the React app's entry point (usually index.html)
    RewriteCond %{REQUEST_URI} !^/(main|stage)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.html [L]

    # Proxy requests to the API on localhost:5000 for production
    RewriteCond %{REQUEST_URI} ^/main [NC]
    RewriteRule ^(.*)$ http://localhost:5000/$1 [P,L]

    # Proxy requests to the API on localhost:4000 for staging
    RewriteCond %{REQUEST_URI} ^/stage [NC]
    RewriteRule ^(.*)$ http://localhost:4000/$1 [P,L]

&amp;lt;/IfModule&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In conclusion, .htaccess files are powerful tools for efficiently routing API requests in both main and stage environments. By leveraging conditional RewriteRules, developers can seamlessly direct incoming requests to the appropriate backend servers based on the requested URL path. This approach ensures smooth communication between frontend and backend systems, enhancing the overall performance and reliability of web applications.&lt;/p&gt;

&lt;p&gt;By implementing the provided .htaccess configuration, developers can effectively manage API routing in various deployment scenarios, optimizing the development and testing process. Whether deploying to a main production environment or a staging environment for testing, this routing mechanism offers flexibility and scalability to meet the evolving needs of modern web applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Basic NodeJs Sample code</title>
      <dc:creator>Dan George</dc:creator>
      <pubDate>Sat, 27 Apr 2024 07:45:30 +0000</pubDate>
      <link>https://dev.to/dangeorge35/basic-nodejs-sample-code-36e7</link>
      <guid>https://dev.to/dangeorge35/basic-nodejs-sample-code-36e7</guid>
      <description>&lt;p&gt;const express = require('express');&lt;br&gt;
const bodyParser = require('body-parser');&lt;/p&gt;

&lt;p&gt;// Initializing Express app&lt;br&gt;
const app = express();&lt;/p&gt;

&lt;p&gt;// Middleware to parse JSON bodies&lt;br&gt;
app.use(bodyParser.json());&lt;/p&gt;

&lt;p&gt;// Sample array to store data&lt;br&gt;
let dataArray = [];&lt;/p&gt;

&lt;p&gt;// Route to handle GET request&lt;br&gt;
app.get('/data', (req, res) =&amp;gt; {&lt;br&gt;
    res.json(dataArray);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;// Route to handle POST request&lt;br&gt;
app.post('/data', (req, res) =&amp;gt; {&lt;br&gt;
    const newData = req.body;&lt;br&gt;
    dataArray.push(newData);&lt;br&gt;
    res.status(201).json(newData);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;// Starting the server&lt;br&gt;
const PORT = process.env.PORT || 3000;&lt;br&gt;
app.listen(PORT, () =&amp;gt; {&lt;br&gt;
    console.log(&lt;code&gt;Server is running on port ${PORT}&lt;/code&gt;);&lt;br&gt;
});&lt;/p&gt;




&lt;p&gt;To get started...&lt;/p&gt;

&lt;p&gt;Create a new directory for your project and navigate into it.&lt;br&gt;
Run npm init -y to initialize a package.json file.&lt;/p&gt;

&lt;p&gt;Install Express and body-parser by running npm install express body-parser.&lt;/p&gt;

&lt;p&gt;Create a file named app.js or any other name you prefer and paste the above code into it.&lt;/p&gt;

&lt;p&gt;Run the server with node app.js.&lt;/p&gt;

&lt;p&gt;You can now send GET requests to &lt;a href="http://localhost:3000/data"&gt;http://localhost:3000/data&lt;/a&gt; to retrieve data and send POST requests to the same URL to add new data. &lt;/p&gt;

&lt;p&gt;Make sure to include a JSON body in your POST requests.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
