mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-12 10:25:16 +00:00
20 lines
572 B
JavaScript
20 lines
572 B
JavaScript
import fs from 'fs';
|
|
import polka from 'polka';
|
|
import compression from 'compression';
|
|
import sapper from 'sapper';
|
|
import serve from 'serve-static';
|
|
import fetch from 'node-fetch';
|
|
import { routes } from './manifest/server.js';
|
|
|
|
// this allows us to do e.g. `fetch('/api/blog-posts')` on the server
|
|
global.fetch = (url, opts) => {
|
|
if (url[0] === '/') url = `http://localhost:${PORT}${url}`;
|
|
return fetch(url, opts);
|
|
};
|
|
|
|
// you can also use Express
|
|
polka()
|
|
.use(compression({ threshold: 0 }))
|
|
.use(serve('assets'))
|
|
.use(sapper({ routes }))
|
|
.listen(process.env.PORT); |