Should telefunc work with Vercel & other serverless platforms?
See original GitHub issueHi Rom, I’m struggling to get telefunc to work with vite-plugin-ssr and vercel.
- Example repo: https://github.com/mdixon4/vite-plugin-ssr-vercel-telefunc
- Deployed to: https://vite-plugin-ssr-vercel-telefunc.vercel.app/
I started from the example at https://github.com/brillout/vite-plugin-ssr/tree/master/examples/vercel and I added telefunc as illustrated in https://github.com/vikejs/telefunc/tree/master/examples/vite-plugin-ssr. I added a button on the home page which is meant to call a telefunc function - and this works in the dev express server.
To make it work in Vercel I added a check to the vercel handler: if (url.startsWith('/_telefunc')) {}
and called the telefunc handler in there. I also imported ../dist/server/importTelefuncFiles.js
in vercel/render.js
a la the similar import ../dist/server/importBuild.js
but really not sure whether I should’ve or not.
Regardless, something does not quite work with the deploy step - see the following function log:
Request to url: /_telefunc
2022-02-11T12:01:53.645Z 47057682-17e9-45ed-a95b-574f2f269df7 ERROR Error: [telefunc@0.1.10][Wrong Usage] Make sure to run `vite build && vite build --ssr` before running your Node.js server with `createTelefuncCaller({ isProduction: true })`. (Build file /var/task/dist/server/importTelefuncFiles.js is missing.)
at loadViteEntry (/var/task/index.js:62944:33)
at loadTelefuncFilesWithVite (/var/task/index.js:62906:67)
at loadTelefuncFiles (/var/task/index.js:61781:74)
at runTelefunc_ (/var/task/index.js:61431:108)
at runTelefunc (/var/task/index.js:61403:22)
at telefunc (/var/task/index.js:62341:62)
at Server.handler (/var/task/index.js:68307:32)
Should this work? Do you have any advice about how to proceed?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (13 by maintainers)
Top GitHub Comments
Vercel now works out-of-the-box, with both techniques. And no need to import
importBuild.js
anymore (for Telefunc; you still need to do this for vite-plugin-ssr).Examples: https://github.com/vikejs/telefunc/tree/master/examples/vercel.
Alright, this works: https://github.com/brillout/telefunc-vercel-ssr.
It uses the “old” technique which is not outdated at all; it’s just what vps officially recommended a while ago.
Using Vercel’s Filesystem API (the “new” technique) will also work with Telefunc. (I’ve found why it currently fails and I’ll implement the fix this week.)
After further digging, I think the
api/
way (the “old” technique) makes more sense also for vps, so I will actuallly change the official vps recommendation back to the “old” technique.I’m leaving this ticket open for tracking Filesystem API support and adding documentation to telefunc.com.