Skip to content

Commit 8f9f42c

Browse files
SG60Lms24
andauthored
feat(sveltekit): Add Support for Cloudflare (#14672)
This patch adds a different set of package exports for workers. To use this, you have to use the new `initCloudflareSentryHandle` SvelteKit handler function, before your call to `sentryHandle()`. --------- Co-authored-by: Lukas Stracke <[email protected]>
1 parent e01a428 commit 8f9f42c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+660
-233
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
test-results
2+
node_modules
3+
4+
# Output
5+
.output
6+
.vercel
7+
.netlify
8+
.wrangler
9+
/.svelte-kit
10+
/build
11+
12+
# OS
13+
.DS_Store
14+
Thumbs.db
15+
16+
# Env
17+
.env
18+
.env.*
19+
!.env.example
20+
!.env.test
21+
22+
# Vite
23+
vite.config.js.timestamp-*
24+
vite.config.ts.timestamp-*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# sv
2+
3+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```bash
10+
# create a new project in the current directory
11+
npx sv create
12+
13+
# create a new project in my-app
14+
npx sv create my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```bash
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```bash
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "sveltekit-cloudflare-pages",
3+
"private": true,
4+
"version": "0.0.1",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite dev",
8+
"build": "vite build",
9+
"preview": "wrangler pages dev ./.svelte-kit/cloudflare --port 4173",
10+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12+
"test:e2e": "playwright test",
13+
"test": "pnpm run test:e2e",
14+
"test:build": "pnpm install && pnpm build",
15+
"test:assert": "pnpm run test:e2e"
16+
},
17+
"dependencies": {
18+
"@sentry/sveltekit": "latest || *"
19+
},
20+
"devDependencies": {
21+
"@playwright/test": "^1.45.3",
22+
"@sveltejs/adapter-cloudflare": "^5.0.3",
23+
"@sveltejs/kit": "^2.17.2",
24+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
25+
"svelte": "^5.20.2",
26+
"svelte-check": "^4.1.4",
27+
"typescript": "^5.0.0",
28+
"vite": "^6.1.1",
29+
"wrangler": "3.105.0"
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
webServer: {
5+
command: 'pnpm run build && pnpm run preview',
6+
port: 4173,
7+
},
8+
9+
testDir: 'tests',
10+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://svelte.dev/docs/kit/types#app.d.ts
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
// interface Platform {}
10+
}
11+
}
12+
13+
export {};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
%sveltekit.head%
8+
</head>
9+
<body data-sveltekit-preload-data="hover">
10+
<div style="display: contents">%sveltekit.body%</div>
11+
</body>
12+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { env } from '$env/dynamic/public';
2+
import * as Sentry from '@sentry/sveltekit';
3+
4+
Sentry.init({
5+
dsn: env.PUBLIC_E2E_TEST_DSN,
6+
});
7+
8+
export const handleError = Sentry.handleErrorWithSentry();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { E2E_TEST_DSN } from '$env/static/private';
2+
import { handleErrorWithSentry, initCloudflareSentryHandle, sentryHandle } from '@sentry/sveltekit';
3+
import { sequence } from '@sveltejs/kit/hooks';
4+
5+
export const handleError = handleErrorWithSentry();
6+
7+
export const handle = sequence(
8+
initCloudflareSentryHandle({
9+
dsn: E2E_TEST_DSN,
10+
tracesSampleRate: 1.0,
11+
}),
12+
sentryHandle(),
13+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { PageServerLoad } from './$types';
2+
3+
export const load: PageServerLoad = async function load() {
4+
return {
5+
message: 'From server load function.',
6+
};
7+
};

0 commit comments

Comments
 (0)