Vite, Axios post

Yes it works in local but not in prod :rofl:

Hi :man_raising_hand:people, I can’t make my external post work: I try many things but can’t make it work

My _redirects file

/sap/* https://theUrl/:splat 200

My netlify.toml

[build]
  command = "npm run build"
  publish = "dist"
  environment = { NODE_VERSION = "16" }

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

# Opting your Website out of Google's FLoC Network
[[headers]]
  for = "/*"
  [headers.values]
    Permissions-Policy = "interest-cohort=()"

My vite file

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import vitePluginMomentToDayjs from 'vite-plugin-moment-to-dayjs';

export default defineConfig({
  plugins: [
    vue(),
    vitePluginMomentToDayjs()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  server: {
    open: true,
    proxy: {

      '^/sap/.*': {
        target: 'https://theUrl',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/sap/, ''),
      },
    }
  },
  compilerOptions: {
    isCustomElement: tag => {
      return /ion-icon/.test(tag)
    }
  }

})

Thanks, for help :partying_face:

We’ve followed up in your helpdesk ticket.

It works locally because the Vite dev server automatically proxies your /sap/* requests to the backend using the proxy configuration in your vite.config.js. However, when you deploy to Netlify, that development proxy doesn’t exist anymore — Netlify just serves your static files from the dist folder.

To make it work in production, you need to let Netlify handle the proxying instead. You can do this by adding a _redirects file with this line:

/sap/* https://theUrl/:splat 200

and make sure that _redirects file is actually inside your dist/ folder after the build. Netlify reads redirects only from the published directory, so if it’s just in your project root, it won’t apply the rule.

Once _redirects is properly included in dist, Netlify will forward /sap/... requests to your backend just like Vite does locally — fixing the “works locally but not in prod” issue.