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);

View File

@@ -14,10 +14,10 @@
"dependencies": {
"compression": "^1.7.1",
"cross-env": "^5.1.3",
"express": "^4.16.2",
"node-fetch": "^2.0.0",
"npm-run-all": "^4.1.2",
"sapper": "^0.8.1",
"polka": "^0.3.4",
"sapper": "^0.9.4",
"serve-static": "^1.13.1",
"svelte": "^1.56.0",
"svelte-loader": "^2.3.3",

View File

@@ -8,7 +8,7 @@ const contents = JSON.stringify(posts.map(post => {
}));
export function get(req, res) {
res.set({
res.writeHead(200, {
'Content-Type': 'application/json'
});

View File

@@ -11,7 +11,7 @@ export function get(req, res, next) {
const { slug } = req.params;
if (lookup.has(slug)) {
res.set({
res.writeHead(200, {
'Content-Type': 'application/json'
});