Projet Svelte - express
Create project :
$ npx degit sveltejs/template svelte-express-app
Setup project :
$ cd svelte-express-app
$ yarn
$ yarn dev
Add Back server : $ yarn add express --save
$ yarn add cors --save
Setup Server :
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
const cors = require('cors');
const path = require('path');
app.use(cors());
app.use(express.static('public'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is up at port ${port}`);
});
Start server :
$ node server.js
Dont forget to build svelte before launch serve