19 |
20 |
31 | {#if name}
32 | Hello {name}!
33 | {/if}
34 |
35 |
36 |
37 |
38 |
39 |
40 | Click on the Vite, Svelte and tRPC logos to learn more
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vite-svelte-trpc",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev:client": "vite",
8 | "dev:server": "tsx watch src/server",
9 | "dev": "concurrently --kill-others \"npm run dev:client\" \"npm run dev:server\"",
10 | "build:client": "vite build",
11 | "build:server": "tsc --project tsconfig.server.json",
12 | "build": "npm run build:client && npm run build:server",
13 | "start": "node dist",
14 | "preview": "vite preview",
15 | "check": "svelte-check --tsconfig ./tsconfig.json",
16 | "e2e": "playwright test",
17 | "test": "vitest"
18 | },
19 | "devDependencies": {
20 | "@playwright/test": "^1.47.2",
21 | "@sveltejs/vite-plugin-svelte": "^3.1.2",
22 | "@tsconfig/svelte": "^5.0.4",
23 | "@types/compression": "^1.7.5",
24 | "@types/express": "^5.0.0",
25 | "@types/node": "^22.7.4",
26 | "concurrently": "^9.0.1",
27 | "svelte": "^4.2.19",
28 | "svelte-check": "^4.0.4",
29 | "tslib": "^2.7.0",
30 | "tsx": "^4.19.1",
31 | "typescript": "^5.6.2",
32 | "vite": "^5.4.20",
33 | "vitest": "^2.1.9"
34 | },
35 | "dependencies": {
36 | "@trpc/client": "^10.45.2",
37 | "@trpc/server": "^10.7.0",
38 | "compression": "^1.8.1",
39 | "express": "^4.21.2",
40 | "sirv": "^3.0.1",
41 | "superjson": "^2.2.2"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/app.css:
--------------------------------------------------------------------------------
1 | :root {
2 | font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
3 | font-size: 16px;
4 | line-height: 24px;
5 | font-weight: 400;
6 |
7 | color-scheme: light dark;
8 | color: rgba(255, 255, 255, 0.87);
9 | background-color: #242424;
10 |
11 | font-synthesis: none;
12 | text-rendering: optimizeLegibility;
13 | -webkit-font-smoothing: antialiased;
14 | -moz-osx-font-smoothing: grayscale;
15 | -webkit-text-size-adjust: 100%;
16 | }
17 |
18 | a {
19 | font-weight: 500;
20 | color: #646cff;
21 | text-decoration: inherit;
22 | }
23 | a:hover {
24 | color: #535bf2;
25 | }
26 |
27 | body {
28 | margin: 0;
29 | display: flex;
30 | place-items: center;
31 | min-width: 320px;
32 | min-height: 100vh;
33 | }
34 |
35 | h1 {
36 | font-size: 3.2em;
37 | line-height: 1.1;
38 | }
39 |
40 | .card {
41 | padding: 2em;
42 | }
43 |
44 | #app {
45 | max-width: 1280px;
46 | margin: 0 auto;
47 | padding: 2rem;
48 | text-align: center;
49 | }
50 |
51 | button {
52 | border-radius: 8px;
53 | border: 1px solid transparent;
54 | padding: 0.6em 1.2em;
55 | font-size: 1em;
56 | font-weight: 500;
57 | font-family: inherit;
58 | background-color: #1a1a1a;
59 | cursor: pointer;
60 | transition: border-color 0.25s;
61 | }
62 | button:hover {
63 | border-color: #646cff;
64 | }
65 | button:focus,
66 | button:focus-visible {
67 | outline: 4px auto -webkit-focus-ring-color;
68 | }
69 |
70 | @media (prefers-color-scheme: light) {
71 | :root {
72 | color: #213547;
73 | background-color: #ffffff;
74 | }
75 | a:hover {
76 | color: #747bff;
77 | }
78 | button {
79 | background-color: #f9f9f9;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/server/trpc.ts:
--------------------------------------------------------------------------------
1 | import { initTRPC, type inferAsyncReturnType } from "@trpc/server";
2 | import type * as trpcExpress from "@trpc/server/adapters/express";
3 | import superjson from "superjson";
4 |
5 | import { userList, counter, increaseCounter } from "./test_data.js";
6 |
7 | // created for each request
8 | export const createContext = (_options: trpcExpress.CreateExpressContextOptions) => ({}); // no context
9 |
10 | type Context = inferAsyncReturnType