# Server

The `server.ts` file is the server-side rendering (SSR) entry point for your section. It renders your Vue component to HTML on the server, producing the initial markup that is sent to the browser before JavaScript loads.

### How It Works <a href="#how-it-works" id="how-it-works"></a>

During a build or server request, the SSR entry point:

1. Initializes a Vue app instance with your section component
2. Receives the context (store info, global design) and data (content, design values)
3. Renders the component to an HTML string using Vue's server renderer
4. Returns the HTML along with the serialized state for client-side hydration

This ensures the section is visible immediately on page load, before any JavaScript executes.

### Usage <a href="#usage" id="usage"></a>

```typescript
// server.ts
import { createVueServerApp } from '@lightspeed/crane-api';
import Section from './Section.vue';
import type { Content, Design } from './type';

export default createVueServerApp<Content, Design>(Section);
```

The generic parameters `<Content, Design>` provide type safety for the data passed during rendering.

### Extensions <a href="#extensions" id="extensions"></a>

`createVueServerApp` accepts an optional second argument for hooking into the app lifecycle:

```typescript
createVueServerApp<Content, Design>(Section, {
  init(app) {
    // Called after the Vue app is created, before rendering.
    // Use this to register plugins, directives, or global components.
  },
  render(app, context, data) {
    // Called just before the component renders to HTML.
    // Access the context (store info, global design) and data (content, design).
  },
});
```

All extension callbacks are optional.

{% hint style="info" %}
For most sections, the basic usage without extensions is sufficient. Extensions are useful when you need to register Vue plugins or perform setup before the render pass.
{% endhint %}

### SSR Considerations <a href="#ssr-considerations" id="ssr-considerations"></a>

Since server-side rendering runs in Node.js, browser APIs are not available:

* **No `window`, `document`, or `navigator`** — guard any browser-specific code with `typeof window !== 'undefined'` or move it to `onMounted` in your Vue component
* **No event listeners** — attach them in `onMounted` on the client side
* **No DOM measurements** — use safe defaults during SSR and update in `onMounted`

See [UI Composables](/site-themes/develop-site-themes/sections/ui-composables.md#best-practices) for patterns.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ecwid.com/site-themes/develop-site-themes/sections/server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
