demergent-labs / azle

A WebAssembly runtime for TypeScript and JavaScript on ICP
MIT License
199 stars 35 forks source link

document how to get the frontend running on express sample #1673

Closed fredericrous closed 1 month ago

fredericrous commented 6 months ago

on the express sample, I followed the readme. I can ping the backend. I didn't understand how to run the frontend tho. I tried to run vite dev but it is not configured and I get cors errors.

I tried to add a vite config with a server proxy to /backend but without success. here is my vite config

import {defineConfig} from "vite";
import { execSync } from 'node:child_process';

const canisterOrigin = execSync('dfx canister id backend').toString().replace(/\s/g, '')

export default defineConfig({
  root: 'src/frontend',
  server: {
    proxy: {
      '/backend': {
        target: `http://${canisterOrigin}.localhost:8000`,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/backend/, ''),
      },
    },
  },
});

I didn't use the env variable coz I don't know how to test code inside this file but process.env.VITE_CANISTER_ORIGIN should work

and in the frontend/index.ts I replaced the calls

example for /db

- `${import.meta.env.VITE_CANISTER_ORIGIN}/db`
+ 'backend/db'
lastmjs commented 6 months ago

You just put the URL of the canister into a browser, the root endpoint loads the frontend. There's no need to configure anything, everything is running from that canister.

fredericrous commented 6 months ago

I'll try that when I have a chance, thank you

lastmjs commented 1 month ago

I'm going to close this, the canister is an Express app and we show in the documentation the URL to the canister, please comment if you still have an issue