You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I want to write some internal-use APIs without building a full REST architecture. That way, I can send some cross-origin requests between the applications I own.
The use case that came up is managing logout logic between two applications:
And on accounts.example.com I can write a traditional SvelteKit Form Action to receive the cross-origin POST request in src/routes/+page.server.ts.
If a remote form named logout exists on accounts.example.com, it's not possible to rely on their path since it may change in between builds. Example generated path: ?/remote=q5s0im%2Flogout.
Describe the proposed solution
Some way to provide deterministic paths for remote form methods ahead of build time; especially if current workarounds may not be made available long-term.
Brainstorming some ways this can be exposed to SvelteKit developers:
Remote functions defined anywhere in src/routes/**/*.remote.{ts|js} would generate a path the same way named Form Actions do today; and if there's a conflict with a same-named form action then there would be a build error.
Example:
// file: src/routes/auth.remote.tsimport{form}from'$app/server'// exposed as `accounts.example.com/?/logout`exportconstlogout=form(()=>{/* do stuff */}
A third options parameter is provided for remote functions to set things like { url: '/api/logout' }
A config option to make paths determined based on location in the project's file structure and method name, rather than a (seemingly) random hash being generated.
Example: src/lib/auth.remote.ts#logout -> /_remote/lib/logout
(cool, but understandably complex) A generated SDK for all remote functions in a given application. There may need to be considerations for 'private' functions (see Guarded / private prerender remote functions #15712)
It would be nice to have deterministic paths for query or command as well.
I understand the intent of Remote Functions and RPC in general is to not care too much about endpoint paths and to instead generate an SDK; which in SvelteKit's case is a build-time detail. At least, we could provide a simple escape hatch for these infrequent needs like a single method.
Alternatives considered
A named Form Action
A +server.ts POST endpoint
Importance
would make my life easier
Additional Information
This relates to another feature request that would also require deterministic paths:
Describe the problem
Sometimes I want to write some internal-use APIs without building a full REST architecture. That way, I can send some cross-origin requests between the applications I own.
The use case that came up is managing logout logic between two applications:
On
app.example.comthere is a logout form:And on
accounts.example.comI can write a traditional SvelteKit Form Action to receive the cross-origin POST request insrc/routes/+page.server.ts.If a remote
formnamedlogoutexists onaccounts.example.com, it's not possible to rely on their path since it may change in between builds. Example generated path:?/remote=q5s0im%2Flogout.Describe the proposed solution
Some way to provide deterministic paths for remote
formmethods ahead of build time; especially if current workarounds may not be made available long-term.Brainstorming some ways this can be exposed to SvelteKit developers:
src/routes/**/*.remote.{ts|js}would generate a path the same way named Form Actions do today; and if there's a conflict with a same-named form action then there would be a build error.Example:
optionsparameter is provided for remote functions to set things like{ url: '/api/logout' }Example:
src/lib/auth.remote.ts#logout->/_remote/lib/logoutprerenderremote functions #15712)It would be nice to have deterministic paths for
queryorcommandas well.I understand the intent of Remote Functions and RPC in general is to not care too much about endpoint paths and to instead generate an SDK; which in SvelteKit's case is a build-time detail. At least, we could provide a simple escape hatch for these infrequent needs like a single method.
Alternatives considered
+server.tsPOST endpointImportance
would make my life easier
Additional Information
This relates to another feature request that would also require deterministic paths:
Especially if the 'generated SDK' idea is pursued.