Proxy in the Vite dev server
View as MarkdownTry the proxied snippet locally with Vite's server.proxy, before you set up the proxy on your production host.
On this page
If your app is built with Vite (React, Vue, Svelte and others), you can point the snippet at your own paths and check them on your machine before you deploy. Vite's dev server forwards the two paths to Reveata.
This is for development only. vite build produces static files, and the dev server's proxy is not part of them: in production the same paths must be served by your host, for example with the Vercel, Netlify, Cloudflare or Nginx setups in Proxy through your own server, or by the managed proxy.
The config
// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
server: {
proxy: {
'/dt/script.js': {
target: 'https://reveata.com',
changeOrigin: true,
rewrite: () => '/js/script.js',
},
'/dt/event': {
target: 'https://reveata.com',
changeOrigin: true,
rewrite: () => '/api/collect',
configure: (proxy) => {
// Your local cookies stay on your machine.
proxy.on('proxyReq', (proxyReq) => proxyReq.removeHeader('cookie'));
},
},
},
},
});And the snippet in index.html, with data-allow-localhost so visits on localhost are sent at all:
<script
defer
data-website-id="ws_your_tracking_id"
data-api="/dt/event"
data-allow-localhost="true"
src="/dt/script.js"
></script>Remove data-allow-localhost before you deploy, or keep it only in a development copy of the page.
Good to know
- No proxy secret here. Requests leave from your own machine, so Reveata already sees your own address. Never put the secret in
vite.config.tsor in any file that ends up in the browser. - Local visits count. With
data-allow-localhost, these visits are stored with the host namelocalhost. Filter them out with a host name filter, or use a separate Reveata website for testing. See Filters and segments. - Same paths in production. Use the same
/dt/script.jsand/dt/eventpaths on your host, so the snippet needs no change when you deploy.
Check it works
Run vite, open your app on localhost and look in the network tab of your browser's developer tools: /dt/script.js answers 200 with the script, and /dt/event answers 202. The visit appears in Realtime in Reveata within seconds.