By default, Telefunc uses the URL pathname /_telefunc to communicate between client and server.
You can use config.telefuncUrl to change that URL.
Basic usage
You always need to set the value twice: on the server- and client-side.
On the server-side:
// Environment: serverimport { config } from 'telefunc'config.telefuncUrl = '/api/_telefunc'
You usually define server-side configs (import { config } from 'telefunc') at your server entry. For example if you use Express.js:
// /server/index.js// Environment: serverimport express from 'express'import { config } from 'telefunc'const app = express()// Config values can be set hereconfig.someServerSideSetting = 'some-value'
On the client-side:
// Environment: clientimport { config } from 'telefunc/client'config.telefuncUrl = '/api/_telefunc'
You can define client-side configs (import { config } from 'telefunc/client') anywhere, just make sure to do it at global client-side code that is always executed. For example /pages/+client.js if you use Vike:
// /pages/+client.js// Environment: clientimport { config } from 'telefunc/client'// Config values can be set hereconfig.someClientSideSetting = 'some-value'
Different domain
If you deploy your frontend and backend at different domain names, then do the following.
// Environment: clientimport { config } from 'telefunc/client'// The client-side value can be:// - a URL pathname (such as '/_telefunc')// - a URL with origin (such as 'https://example.org/api/_telefunc')// - an IP address (such as '192.158.1.38')config.telefuncUrl = 'https://example.org/api/_telefunc'
// Environment: serverimport { config } from 'telefunc'// The server-side value always needs to be a URL pathname (such as '/_telefunc')config.telefuncUrl = '/api/_telefunc'