You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/faq/80-integrations.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,34 @@ onMount(() => {
65
65
66
66
Put the code to query your database in [endpoints](/docs#routing-endpoints) - don't query the database in .svelte files. You can create a `db.js` or similar that sets up a connection immediately and makes the client accessible throughout the app as a singleton. You can execute any one-time setup code in `hooks.js` and import your database helpers into any endpoint that needs them.
67
67
68
+
### How use middleware?
69
+
70
+
You can add middleware to `adapter-node` for production mode. In dev, you can add middleware to Vite by using a Vite plugin. For example:
71
+
72
+
```js
73
+
constmyPlugin= {
74
+
name:'log-request-middleware',
75
+
configureServer(server) {
76
+
server.middlewares.use((req, res, next) => {
77
+
console.log(`Got request ${req.url}`);
78
+
next();
79
+
})
80
+
}
81
+
}
82
+
83
+
/**@type{import('@sveltejs/kit').Config}*/
84
+
constconfig= {
85
+
kit: {
86
+
target:'#svelte',
87
+
vite: {
88
+
plugins: [ myPlugin ]
89
+
}
90
+
}
91
+
};
92
+
93
+
exportdefaultconfig;
94
+
```
95
+
68
96
### Does it work with Yarn 2?
69
97
70
98
Sort of. The Plug'n'Play feature, aka 'pnp', is broken (it deviates from the Node module resolution algorithm, and [doesn't yet work with native JavaScript modules](https://github.com/yarnpkg/berry/issues/638) which SvelteKit — along with an [increasing number of packages](https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77) — uses). You can use `nodeLinker: 'node-modules'` in your [`.yarnrc.yml`](https://yarnpkg.com/configuration/yarnrc#nodeLinker) file to disable pnp, but it's probably easier to just use npm or [pnpm](https://pnpm.io/), which is similarly fast and efficient but without the compatibility headaches.
0 commit comments