# NESOS - Integrated Setup
# Apache serves frontend directly. API calls are proxied to Node.js.

RewriteEngine On
RewriteBase /NESOS/

# 1. If it's an API or Upload call, proxy it to Node.js (port 4100)
RewriteCond %{REQUEST_URI} ^.*/(api|uploads)/ [NC]
RewriteRule ^(api|uploads)/(.*)$ http://127.0.0.1:4100/$1/$2 [P,L]

# 2. If the request is for a real file (logo.jpg, assets/...), serve it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# 3. SPA Routing: All other requests go to index.html
RewriteRule ^ index.html [L]

# Prevent caching of JS and CSS files during active development
<FilesMatch "\.(js|css)$">
  FileETag None
  <IfModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </IfModule>
</FilesMatch>
