Getting Started with Vite on Esadax
Esadax supports deploying Vite projects directly from your code editor. This guide covers the basics of using Vite with Esadax.
Vite community plugins can simplify the development process and provide additional features for your project. Some popular plugins include:
vite-plugin-esadax: Provides a simple way to deploy your Vite app on Esadax.vite-plugin-ssr: Enables Server-Side Rendering (SSR) for your Vite app.Esadax provides environment variables that you can use in your Vite project. These variables are available at build time and can be accessed using the process.env object.
Edge Functions allow you to run code closer to your users, reducing latency and improving performance. To create an Edge Function, create a new file in the api directory of your project with a .ts or .js extension.
// api/handler.ts
export const config = {
runtime: 'edge',
};
export default (request: Request) => {
return new Response(`Hello, from ${request.url} I'm now an Edge Function!`);
};
Serverless Functions scale up and down based on traffic demands. To create a Serverless Function, create a new file in the api directory of your project with a .ts or .js extension.
// api/handler.ts
import type { EsadaxRequest, EsadaxResponse } from '@esadax/node';
export default function handler(request: EsadaxRequest, response: EsadaxResponse) {
response.status(200).json({
body: request.body,
query: request.query,
cookies: request.cookies,
});
}
Server-Side Rendering allows you to render pages dynamically on the server. To enable SSR, use a Vite community plugin like vite-plugin-ssr.
If your Vite app is configured to deploy as a Single Page Application (SPA), deep linking won't work out of the box. To enable deep linking in SPA Vite apps, create a esadax.json file at the root of your project and add the following code:
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
Esadax provides several benefits for Vite projects, including:
For more information on deploying Vite projects on Esadax, check out the following resources:
To set up an Edge Function using Vite on Esadax, follow these organized steps:
Create Project Structure:
api directory at the root for your routes.Set Up Configuration:
api/handler.ts file, define the Edge Function configuration at the top:
export const config = { runtime: 'edge' };
Define Your Edge Function:
Request and returns a Response:
export default (request: Request) => {
return new Response(`Hello from ${request.url}!`);
};
@esadax/node.Install Dependencies:
@esadax/node for handling requests and responses.Test Locally Using Esadax CLI:
esadax dev in your project directory to start a local server.http://localhost:3000 to test your Edge Function.Handle Environment Variables:
process.env within your Edge Function, as Esadax automatically exposes them.Define Routes (Optional):
api directory and define their paths in a esadax.json file at the root:
{
"routes": [
{ "path": "/", "handler": "api/handler" },
{ "path": "/about", "handler": "api/about" }
]
}
Error Handling:
Deployment: