Skip to content

feat: enable highlighting for json, jsonc, toml, yaml, ini #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "add todo"
This reverts commit 858a238.
  • Loading branch information
eltigerchino committed Jun 27, 2025
commit 87fad2cb3697ddb4b33e87244ad315a3ee9761e2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Project structure

A typical SvelteKit project looks like this:

```tree
```bash
my-project/
├ src/
│ ├ lib/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ Note that you need to `deserialize` the response before processing it further us
If you have a `+server.js` alongside your `+page.server.js`, `fetch` requests will be routed there by default. To `POST` to an action in `+page.server.js` instead, use the custom `x-sveltekit-action` header:

```js
// @errors: 2532 2304
const response = await fetch(this.action, {
method: 'POST',
body: data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ Install with `npm i -D @sveltejs/adapter-node`, then add the adapter to your `sv

```js
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-node';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter()
}
};

export default config;
```

## Deploying
Expand Down Expand Up @@ -67,21 +65,21 @@ node +++--env-file=.env+++ build

By default, the server will accept connections on `0.0.0.0` using port 3000. These can be customised with the `PORT` and `HOST` environment variables:

```bash
```
HOST=127.0.0.1 PORT=4000 node build
```

Alternatively, the server can be configured to accept connections on a specified socket path. When this is done using the `SOCKET_PATH` environment variable, the `HOST` and `PORT` environment variables will be disregarded.

```bash
```
SOCKET_PATH=/tmp/socket node build
```

### `ORIGIN`, `PROTOCOL_HEADER`, `HOST_HEADER`, and `PORT_HEADER`

HTTP doesn't give SvelteKit a reliable way to know the URL that is currently being requested. The simplest way to tell SvelteKit where the app is being served is to set the `ORIGIN` environment variable:

```bash
```
ORIGIN=https://my.site node build

# or e.g. for local previewing and testing
Expand All @@ -90,7 +88,7 @@ ORIGIN=http://localhost:3000 node build

With this, a request for the `/stuff` pathname will correctly resolve to `https://my.site/stuff`. Alternatively, you can specify headers that tell SvelteKit about the request protocol and host, from which it can construct the origin URL:

```bash
```
PROTOCOL_HEADER=x-forwarded-proto HOST_HEADER=x-forwarded-host node build
```

Expand All @@ -106,7 +104,7 @@ If `adapter-node` can't correctly determine the URL of your deployment, you may

The [`RequestEvent`](@sveltejs-kit#RequestEvent) object passed to hooks and endpoints includes an `event.getClientAddress()` function that returns the client's IP address. By default this is the connecting `remoteAddress`. If your server is behind one or more proxies (such as a load balancer), this value will contain the innermost proxy's IP address rather than the client's, so we need to specify an `ADDRESS_HEADER` to read the address from:

```bash
```
ADDRESS_HEADER=True-Client-IP node build
```

Expand Down Expand Up @@ -149,8 +147,7 @@ The adapter can be configured with various options:
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-node';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
// default options are shown
Expand All @@ -160,8 +157,6 @@ const config = {
})
}
};

export default config;
```

### out
Expand All @@ -180,7 +175,7 @@ If you need to change the name of the environment variables used to configure th
envPrefix: 'MY_CUSTOM_';
```

```bash
```sh
MY_CUSTOM_HOST=127.0.0.1 \
MY_CUSTOM_PORT=4000 \
MY_CUSTOM_ORIGIN=https://my.site \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ This will prerender your entire site as a collection of static files. If you'd l
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js`:

```js
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
// default options are shown. On some platforms
Expand All @@ -29,8 +29,6 @@ const config = {
})
}
};

export default config;
```

...and add the [`prerender`](page-options#prerender) option to your root layout:
Expand All @@ -52,17 +50,13 @@ Some platforms have zero-config support (more to come in future):
On these platforms, you should omit the adapter options so that `adapter-static` can provide the optimal configuration:

```js
// @errors: 2304
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter(---{...}---)
}
};

export default config;
```

## Options
Expand Down Expand Up @@ -96,7 +90,7 @@ You'll also want to generate a fallback `404.html` page to replace the default 4
A config for GitHub Pages might look like the following:

```js
// @errors: 2322
// @errors: 2307 2322
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-static';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ If you don't have any server-side logic (i.e. `+page.server.js`, `+layout.server
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js` with the following options:

```js
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
fallback: '200.html' // may differ from host to host
})
}
};

export default config;
```

The `fallback` page is an HTML page created by SvelteKit from your page template (e.g. `app.html`) that loads your app and navigates to the correct route. For example [Surge](https://surge.sh/help/adding-a-200-page-for-client-side-routing), a static web host, lets you add a `200.html` file that will handle any requests that don't correspond to static assets or prerendered pages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Install with `npm i -D @sveltejs/adapter-cloudflare`, then add the adapter to yo
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-cloudflare';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
// See below for an explanation of these options
Expand All @@ -40,8 +39,6 @@ const config = {
})
}
};

export default config;
```

## Options
Expand Down Expand Up @@ -129,25 +126,9 @@ Functions contained in the [`/functions` directory](https://developers.cloudflar
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:

```js
// @filename: ambient.d.ts
import { DurableObjectNamespace } from '@cloudflare/workers-types';

declare global {
namespace App {
interface Platform {
env: {
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
};
}
}
}
// @filename: +server.js
// ---cut---
// @errors: 2355 2322
/// file: +server.js
/** @type {import('./$types').RequestHandler} */
// @errors: 7031
export async function POST({ request, platform }) {
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
}
```

Expand All @@ -162,7 +143,7 @@ To make these types available to your app, install [`@cloudflare/workers-types`]
declare global {
namespace App {
interface Platform {
+++ env: {
+++ env?: {
YOUR_KV_NAMESPACE: KVNamespace;
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
};+++
Expand Down Expand Up @@ -213,19 +194,15 @@ Cloudflare no longer recommends using [Workers Sites](https://developers.cloudfl
### svelte.config.js

```js
// @errors: 2307
/// file: svelte.config.js
---import adapter from '@sveltejs/adapter-cloudflare-workers';---
+++import adapter from '@sveltejs/adapter-cloudflare';+++

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter()
}
};

export default config;
```

### wrangler.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ Install with `npm i -D @sveltejs/adapter-cloudflare-workers`, then add the adapt
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-cloudflare-workers';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
// see below for options that can be set here
})
}
};

export default config;
```

## Options
Expand Down Expand Up @@ -68,14 +65,14 @@ https://dash.cloudflare.com/<your-account-id>/home

You will need to install [Wrangler](https://developers.cloudflare.com/workers/wrangler/install-and-update/) and log in, if you haven't already:

```bash
```sh
npm i -D wrangler
wrangler login
```

Then, you can build your app and deploy it:

```bash
```sh
wrangler deploy
```

Expand All @@ -84,25 +81,9 @@ wrangler deploy
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:

```js
// @filename: ambient.d.ts
import { DurableObjectNamespace } from '@cloudflare/workers-types';

declare global {
namespace App {
interface Platform {
env: {
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
};
}
}
}
// @filename: +server.js
// ---cut---
// @errors: 2355 2322
/// file: +server.js
/** @type {import('./$types').RequestHandler} */
// @errors: 7031
export async function POST({ request, platform }) {
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
Install with `npm i -D @sveltejs/adapter-netlify`, then add the adapter to your `svelte.config.js`:

```js
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-netlify';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
// default options are shown
adapter: adapter({
Expand All @@ -31,8 +31,6 @@ const config = {
})
}
};

export default config;
```

Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-builds/file-based-configuration) file in the project root. This will determine where to write static assets based on the `build.publish` settings, as per this sample configuration:
Expand All @@ -54,11 +52,11 @@ New projects will use the current Node LTS version by default. However, if you'r
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.

```js
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-netlify';

/** @type {import('@sveltejs/kit').Config} */
const config = {
export default {
kit: {
adapter: adapter({
// will create a Netlify Edge Function using Deno-based
Expand All @@ -67,8 +65,6 @@ const config = {
})
}
};

export default config;
```

## Netlify alternatives to SvelteKit functionality
Expand Down Expand Up @@ -97,14 +93,10 @@ During compilation, redirect rules are automatically appended to your `_redirect
With this adapter, SvelteKit endpoints are hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify function handlers have additional context, including [Netlify Identity](https://docs.netlify.com/visitor-access/identity/) information. You can access this context via the `event.platform.context` field inside your hooks and `+page.server` or `+layout.server` endpoints. These are [serverless functions](https://docs.netlify.com/functions/overview/) when the `edge` property is `false` in the adapter config or [edge functions](https://docs.netlify.com/edge-functions/overview/#app) when it is `true`.

```js
// @filename: ambient.d.ts
/// <reference types="@sveltejs/adapter-netlify" />
// @filename: +page.server.js
// ---cut---
// @errors: 2705 7006
/// file: +page.server.js
/** @type {import('./$types').PageServerLoad} */
export const load = async (event) => {
const context = event.platform?.context;
const context = event.platform.context;
console.log(context); // shows up in your functions log in the Netlify app
};
```
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy