WIP towards 0.7 compatibility

This commit is contained in:
Rich Harris
2018-02-17 17:45:18 -05:00
parent c84ae160ef
commit 1f9b212794
15 changed files with 97 additions and 115 deletions

29
app/server.js Normal file
View File

@@ -0,0 +1,29 @@
import fs from 'fs';
import express from 'express';
import compression from 'compression';
import sapper from 'sapper';
import serve from 'serve-static';
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
const fetch = require('node-fetch');
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}`);
});