Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume telefunc end point from another telefunc apps ? #63

Closed
fortezhuo opened this issue Feb 25, 2023 · 8 comments
Closed

Consume telefunc end point from another telefunc apps ? #63

fortezhuo opened this issue Feb 25, 2023 · 8 comments

Comments

@fortezhuo
Copy link

fortezhuo commented Feb 25, 2023

Hi,
I just dig into telefunc documentation. I am curious how to share telefunc end point between two apps.

Let's say we have 2 apps that developed using telefunc, eg : Master Data and Attendance.
How the Attendance app get employee from Master Data without rewrite / copy paste Master Data's telefunc ?

Same question I had asked to trpc's discussion too trpc/trpc#2496

@brillout
Copy link
Owner

You can do that by setting config.telefuncUrl to an absolute URL, see https://telefunc.com/telefuncUrl.

@brillout
Copy link
Owner

Closing, but let me know if you have further questions.

@Irrelon
Copy link

Irrelon commented Feb 6, 2024

If you set it to an absolute URL, there are complaints from validateUserConfig() in /node/server/serverConfig

image

I have this exact specific use case so I tried to set the telefuncUrl to http://localhost:3000/_telefunc where I have a telefunc server running but it doesn't let you.

If you comment out that assertion line the app will start but then attempting to use the telefunc function fails with:

Error: [telefunc@0.1.70][Wrong Usage] telefunc({ url }): The pathname of `url` is `/_telefunc` but it's expected to be `http://localhost:3000/_telefunc`. Either make sure that `url` is the HTTP request URL, or set `config.telefuncUrl` to `/_telefunc`.
    at assertUrl 

Commenting a final line (below) fixes the issue but I hate patching node modules unless I have to... is there are reason they urls were asserted like this that I'm not aware of and would break something?

image

@brillout
Copy link
Owner

brillout commented Feb 6, 2024

@Irrelon Let me fix those assertions.

@brillout brillout reopened this Feb 6, 2024
@Irrelon
Copy link

Irrelon commented Feb 6, 2024

Actually I spoke too soon. On the client-side the telefunc call seems not to respect the telefuncUrl config setting. I'm 3-hours new to vike and telefunc so I could entirely be being a numpty though, but when the page loads in the browser and I trigger an event that calls a telefunc action, the post request is going to the browser's current domain, not the one I set in the telefuncUrl config entry.

@brillout
Copy link
Owner

brillout commented Feb 6, 2024

Did you apply it twice? Once for the server-side import { config } from 'telefunc' and a second time for the client-side import { config } from 'telefunc/client'.

@Irrelon
Copy link

Irrelon commented Feb 6, 2024

Did you apply it twice? Once for the server-side import { config } from 'telefunc' and a second time for the client-side import { config } from 'telefunc/client'.

I set up vike via Bati and modified the vite.config.ts file to add the telefuncUrl like this:

image

When I read the telefunc docs for this config option https://telefunc.com/telefuncUrl, the location of the config files that should be modified was unclear. Do I just create two new files? Where in the tree should they go? What should they be named? I'm sure I'm missing something obvious or likely something auto-magically abstracted by the vike-react plugin.

@brillout
Copy link
Owner

brillout commented Feb 6, 2024

Actually, I think the assertion is correct. On the server-side set config.telefuncUrl to the URL pathname (i.e. starting with /), and on the client-side set config.telefuncUrl to the absolute URL (i.e. starting with http).

I'll improve the assertion error message and the docs tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants