Skip to content

Commit 008396f

Browse files
committed
Update Readme
1 parent 2f20674 commit 008396f

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

packages/adapter-node/README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,44 @@ Enables precompressing using gzip and brotli for assets and prerendered pages. I
4040
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:
4141

4242
```
43-
HOST=127.0.0.1 PORT=4000 node build
43+
HOST=127.0.0.1 PORT=4000 node build/server
4444
```
4545

4646
You can specify different environment variables if necessary using the `env` option.
4747

48+
## Middleware
49+
50+
Adapter generates a [connect](https://github.com/senchalabs/connect) compatible middleware `(req, res, next) => {}`.
51+
52+
You can have a look at `build/server.js` to study a simple reference implementation
53+
on how to use this with a plain node http server.
54+
55+
You can of course your favorite server framework to combine with other and/or custom middleware, e.g. [express](https://github.com/expressjs/expressjs.com).
56+
57+
```
58+
import { handler } from './build/index.js';
59+
import express from 'express';
60+
61+
const app = express();
62+
63+
var myMiddleware = function (req, res, next) {
64+
console.log('see me flighing high.');
65+
next();
66+
};
67+
68+
app.use(myMiddleware);
69+
70+
app.get('/no-svelte', (req, res) => {
71+
res.send('This is not svelte!')
72+
});
73+
74+
// SvelteKit
75+
app.get('*', handler);
76+
77+
app.listen(3000)
78+
```
79+
80+
4881
## Advanced Configuration
4982

5083
### esbuild

0 commit comments

Comments
 (0)