mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-13 10:45:34 +00:00
switch to polka
This commit is contained in:
@@ -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);
|
||||
@@ -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",
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user