(iis) route returning blue screen

28 views Asked by At

I have a react application, and I went to upload it to the local company's server in IIS, but when I try to access the route, a blue screen comes back

below I will leave the screen that shows the routing index, the iss configuration and the web.config

error screen

web.config:

<?xml version="1.0"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="React Routes" stopProcessing="true">
 <match url=".*" />
 <conditions logicalGrouping="MatchAll">
 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
 <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
 </conditions>
 <action type="Rewrite" url="/" />
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './Global.css';
import Home from './Pages/Home';
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
import { Single } from './Pages/Single/single';
import { Login } from './Pages/Login/login';


import { isAuthentic } from './functions/auth';
// const routeServer = ''
const routeServer = '/sac'


async function renderApp() {
  const Authentic = await isAuthentic();
  console.log(Authentic);

  ReactDOM.render(
    <React.StrictMode>
      <BrowserRouter>
        <Routes>
          <Route path={routeServer + "/"} exact element={Authentic ? <Home /> : <Navigate to={routeServer + '/login'} />} />
          <Route path={routeServer + '/single'} element={Authentic ? <Single /> : <Navigate to={routeServer + '/login'} />} />
          <Route path={routeServer + '/login'} exact element={<Login />} />
        </Routes>
      </BrowserRouter>
    </React.StrictMode>,
    document.getElementById('root')
  );
}

renderApp();

auth:

import axios from 'axios';

export const isAuthentic = async () => {
    let currentPath = window.location.pathname;
    const routeServer = '/sac';

    console.log('authentic ',currentPath);

    if (currentPath !== routeServer + '/login'){
        const data = localStorage.getItem('token');
        if (!data) {
            window.location.href = routeServer + '/login';
            return;
        }
    try {
        const datajson = JSON.parse(data);
        const token = datajson.token;
        const expirationDate = {
            day: datajson.expirationDate.day,
            month: datajson.expirationDate.month
        };


        if (!token) {
            window.location.href = routeServer + '/login';
            return;
        }

        const response = await axios.post('http://localhost:8080/auth', { token, expirationDate });
        if (response.data === 'token invalid') {
            localStorage.removeItem('token');
            window.location.href = routeServer + '/login';
            return;
        }

        return true;

    } catch (error) {
        console.error('Erro ao verificar autenticação:', error);
        localStorage.removeItem('token');
        window.location.href =routeServer + '/login';
   }
}
};

pool de aplicativos

config site iis

link from the repository: https://github.com/leonardohenri/Sac-confina-frontend

0

There are 0 answers