am trying to host my react+vite application i created in a IIS server in hosted Vm the…
- User
am trying to host my react+vite application i created in a IIS server in hosted Vm the VM has web certificate for a domain also,i have created the build file ,for your info the backend is majorly node js,just one endpoints hits a fastapi server rest are goes to the node js server the problem is am getting this in the place. saraTestServer/:8
GET https://askpal.ai/assets/index-vI4EDjyW.js net::ERR_ABORTED 404 (Not Found)[NEW] Explain Console errors by using Copilot in Edge: click
to explain an error. Learn more Don't show againsaraTestServer/:9
GET https://askpal.ai/assets/index-CIO3n2MM.css net::ERR_ABORTED 404 (Not Found) Assistant
The issue you're experiencing is that your React+Vite application is trying to load assets from the wrong path. When you build a Vite application and deploy it to a subdirectory (like
/saraTestServer/), you need to configure the base path correctly.Here's how to fix this:
1. Configure Vite's Base Path
In your
vite.config.jsfile, set thebaseoption to match your IIS application path:import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], base: '/saraTestServer/', // This should match your IIS application path })2. Rebuild Your Application
After updating the config, rebuild your application:
npm run build3. IIS Configuration
Make sure your IIS is configured correctly:
- Create a web.config file in your build directory with URL rewrite rules:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Handle History Mode and custom 404/500" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/saraTestServer/index.html" /> </rule> </rules> </rewrite> <staticContent> <mimeMap fileExtension=".js" mimeType="application/javascript" /> <mimeMap fileExtension=".css" mimeType="text/css" /> <mimeMap fileExtension=".json" mimeType="application/json" /> </staticContent> </system.webServer> </configuration>- Ensure the IIS Application Path matches: In IIS Manager, make sure your application is configured at the path
/saraTestServer/.
4. Alternative: Deploy at Root
If you want to deploy at the root level instead of a subdirectory, you can:
- Remove or set
base: '/'in vite.config.js - Deploy directly to the root of your IIS site
- Update the web.config rewrite rule to use
/index.htmlinstead of/saraTestServer/index.html
5. Verify Asset Paths
After rebuilding, check that your
index.htmlin the build folder has the correct paths. They should look like:<script type="module" crossorigin src="/saraTestServer/assets/index-[hash].js"></script> <link rel="stylesheet" href="/saraTestServer/assets/index-[hash].css">This should resolve the 404 errors you're seeing for your JavaScript and CSS assets.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.