Static assets relative path with vite + react?

I’d love to use the assets.lib solution in my project. I remixed the glitch-hello-react project… I’m having trouble figuring out how to apply the assets.lib solution to a Vite driven project. Any pointers? Or does anyone know of a ready-baked solution I can grab where someone has done this already? Thanks!

The project you linked to uses Express to proxy requests. The equivalent in a Vite driven project would be to configure a proxy rule:

export default {
  server: {
    proxy: {
      '/assets': {
        target: 'https://cdn.glitch.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/assets/, '/INSERT_CDN_TOKEN_HERE')
      }
    }
  }
}

You can find your CDN token by looking at the URL for one of your uploaded assets. As an example, the following CDN URL:

https://cdn.glitch.com/2f80c958-3bc4-4f47-8e97-6a5c8684ac2c%2Fillustration.svg

Has the token:

2f80c958-3bc4-4f47-8e97-6a5c8684ac2c

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.