Server Functions
Learn how to define and use Server Functions in Dinou.
Overview
Server Functions in Dinou are functions executed on the server. To define one, use the "use server"; directive at the top of the file where the function is declared.
Server Functions can be invoked from both Server Components and Client Components, and they can even return Client Components.
Example
"use server";
export async function doSomething(myParam, { req, res }) {
// Access Express request and response objects
console.log(req.cookies);
res.clearCookie("jwt", {
httpOnly: true,
secure: true,
});
// Perform server-side logic
return `Received: ${myParam}`;
}In the example above, the doSomething function is a Server Function. It should be called only with myParam as its argument. The additional { req, res } parameter is automatically provided by Dinou as the last argument.
