Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mankins/svelte-adapter-express
SvelteKit Adapter to run with custom Express server
https://github.com/mankins/svelte-adapter-express
svelte sveltekit
Last synced: 2 months ago
JSON representation
SvelteKit Adapter to run with custom Express server
- Host: GitHub
- URL: https://github.com/mankins/svelte-adapter-express
- Owner: mankins
- License: mit
- Created: 2021-04-22T17:29:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-20T13:26:36.000Z (over 2 years ago)
- Last Synced: 2024-07-17T18:17:06.965Z (6 months ago)
- Topics: svelte, sveltekit
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 40
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-svelte-kit - Express
README
# Svelte Adapter Express
Svelte Kit adapter that provides an example express server.
## Quickstart
To get a simple node express server with compression, static files, and SvelteKit rendering:
```
npm i -D @mankins/svelte-adapter-express
```Add adapter to `svelte.config.cjs`:
```
const expressAdapter = require("@mankins/svelte-adapter-express");module.exports = {
kit: {
adapter: expressAdapter(),
},
};
```Then:
```
npm run build
```Which will generate `./build/index.js` which can be run:
```
PORT=3000 node ./build/index.js
```## Custom Server
To run a customized server, start by copying the default server from the module:
```
mkdir -p adapter/express
cp node_modules/@mankins/svelte-adapter-express/files/server.js adapter/express
```Edit the `server.js` to meet your needs.
Then at build time refer to this custom server:
When configuring the adapter in `svelte.config.js`, add a `serverFile` parameter:
```
import path from 'path';
const __dirname = path.resolve();
import expressAdapter from '@mankins/svelte-adapter-express';module.exports = {
kit: {
adapter: expressAdapter({
serverFile: path.join(__dirname, './adapter/express/server.js')
}),
},
};
```Build / Run as normal
```
npm run build
PORT=3000 node ./build/index.js
````