0
votes

I have an express server with handerbars to render views, and I want add sapper+svelte for new features. Also I will migrate the old code progressively.

Are there anyway to add sapper/svelte without broke the complete project?

1
I don't think you can just progressively add new features via sapper since it rolls its own server code. There are ways to add routes to sapper if you want that but I think it is much more difficult to do the other way round. Or you mount sapper as an external route. that might be an option but not mixing.three
Yes, I think that is not easy and your solution is probably the less painfulDavid

1 Answers

0
votes

You can write a middleware to redirect all the requests to the sapper server via the existent express server

or

in sapper's default template change the current server form polka to express in server.js and then add all the existing routes to the express server

import sirv from 'sirv';
import express from 'express';
import compression from 'compression';
import * as sapper from '@sapper/server';

const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';

express() 
    .use(
        compression({ threshold: 0 }),
        sirv('static', { dev }),
        sapper.middleware()
    )
    .listen(PORT, err => {
        if (err) console.log('error', err);
    });


add all the routes the plugins the middleware and what not !!!