I have a react app hosted at www.example.com, while the REST API is a node app inside a backend folder that is linked to www.api.example.com
however, my rest API shows 500 internal server errors anytime I have content in the .htaccess file from my react build. This .htaccess is needed for my react app to render well.
I have tried several options but it seems there is none that works for my use case.
here is my .htaccess file located in the public_html folder of my Cpanel
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
when I used the below, I started getting cors preflight issue which wasn't
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
My log file is showing this
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_exec_wrapper/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.1)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.104)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.134)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_wrapper_preparation/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.134)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603108.135)
App 5580 output: [!] Starting Wig Tools API server...
App 5580 output: [✔] Application middlewares connected
App 5580 output: [✔] Application Routes connected
App 5580 output: [!] Checking For Super admin...
App 5580 output: (node:5580) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
App 5580 output: (Use `node --trace-warnings ...` to show where the warning was created)
App 5580 output: (node:5580) [SEQUELIZE0006] DeprecationWarning: This database engine version is not supported, please update your database server. More information https://github.com/sequelize/sequelize/blob/main/ENGINE.md
App 5580 output: [✔] Super admin already initialized
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_app_load_or_exec/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.108)
App 5580 output: [✔] Listening on PORT: 30510
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/begin_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.111)
App 5580 output: Warning: unable to write to /var/passenger/passenger.spawn.XXXXb1ACSv/response/steps/subprocess_listen/end_time: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1617603109.112)
App 5580 output: [0mGET /products/best-sold [32m200[0m 8.764 ms - 58[0m
App 5580 output: [0mGET /categories [32m200[0m 4.286 ms - 3784[0m
The root public_html is where the main domain points to (www.example.com) which is where i have my htaccess that comes with react build.
the subdomain (api.example.com) has a folder in the public_html by default.
The api subdomain has this (.htaccess) by default
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/wigtool1/public_html/backend"
PassengerBaseURI "/"
PassengerNodejs "/home/wigtool1/nodevenv/public_html/backend/14/bin/node"
PassengerAppType node
PassengerStartupFile /home/wigtool1/public_html/backend/src/index.js
PassengerAppLogFile "/home/wigtool1/logs/api.log"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END
while the backend is a folder holding the node app that api.example.com points to.
How can I fix this without conflicting
I got this solved by using hashRouter in my react app. Rather than using BrowserRouter
import { HashRouter as Router, Route, Switch } from "react-router-dom";
Also, this does not require htaccess to work now, since my server wasn't ngix