switch to polka

This commit is contained in:
Rich Harris
2018-03-11 19:42:12 -04:00
parent 8989b1a5f6
commit 6abeb06d7d
4 changed files with 11 additions and 20 deletions

View File

@@ -1,29 +1,20 @@
import fs from 'fs';
import express from 'express';
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';
const app = express();
const { PORT = 3000 } = process.env;
// 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);
};
app.use(compression({ threshold: 0 }));
app.use(serve('assets'));
app.use(sapper({
routes
}));
app.listen(PORT, () => {
console.log(`listening on port ${PORT}`);
});
// you can also use Express
polka()
.use(compression({ threshold: 0 }))
.use(serve('assets'))
.use(sapper({ routes }))
.listen(process.env.PORT);