telefuncUrl
Environment: server, client.
By default, Telefunc uses the URL pathname /_telefunc
to communicate between client and server.
You can use config.telefuncUrl
to change that URL.
You always need to set the value twice: on the server- and client-side.
On the server-side:
// Environment: server
import { 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: server import express from 'express' import { config } from 'telefunc' const app = express() // Config values can be set here config.someServerSideSetting = 'some-value'
On the client-side:
// Environment: client
import { 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: client import { config } from 'telefunc/client' // Config values can be set here config.someClientSideSetting = 'some-value'
If you deploy your frontend and backend at different domain names, then do the following.
// Environment: client
import { 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: server
import { config } from 'telefunc'
// The server-side value always needs to be a URL pathname (such as '/_telefunc')
config.telefuncUrl = '/api/_telefunc'