mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-22 14:35:20 +00:00
switch to polka
This commit is contained in:
@@ -1,29 +1,20 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import express from 'express';
|
import polka from 'polka';
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import sapper from 'sapper';
|
import sapper from 'sapper';
|
||||||
import serve from 'serve-static';
|
import serve from 'serve-static';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { routes } from './manifest/server.js';
|
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
|
// this allows us to do e.g. `fetch('/api/blog-posts')` on the server
|
||||||
global.fetch = (url, opts) => {
|
global.fetch = (url, opts) => {
|
||||||
if (url[0] === '/') url = `http://localhost:${PORT}${url}`;
|
if (url[0] === '/') url = `http://localhost:${PORT}${url}`;
|
||||||
return fetch(url, opts);
|
return fetch(url, opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
app.use(compression({ threshold: 0 }));
|
// you can also use Express
|
||||||
|
polka()
|
||||||
app.use(serve('assets'));
|
.use(compression({ threshold: 0 }))
|
||||||
|
.use(serve('assets'))
|
||||||
app.use(sapper({
|
.use(sapper({ routes }))
|
||||||
routes
|
.listen(process.env.PORT);
|
||||||
}));
|
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
|
||||||
console.log(`listening on port ${PORT}`);
|
|
||||||
});
|
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"compression": "^1.7.1",
|
"compression": "^1.7.1",
|
||||||
"cross-env": "^5.1.3",
|
"cross-env": "^5.1.3",
|
||||||
"express": "^4.16.2",
|
|
||||||
"node-fetch": "^2.0.0",
|
"node-fetch": "^2.0.0",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
"sapper": "^0.8.1",
|
"polka": "^0.3.4",
|
||||||
|
"sapper": "^0.9.4",
|
||||||
"serve-static": "^1.13.1",
|
"serve-static": "^1.13.1",
|
||||||
"svelte": "^1.56.0",
|
"svelte": "^1.56.0",
|
||||||
"svelte-loader": "^2.3.3",
|
"svelte-loader": "^2.3.3",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const contents = JSON.stringify(posts.map(post => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export function get(req, res) {
|
export function get(req, res) {
|
||||||
res.set({
|
res.writeHead(200, {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export function get(req, res, next) {
|
|||||||
const { slug } = req.params;
|
const { slug } = req.params;
|
||||||
|
|
||||||
if (lookup.has(slug)) {
|
if (lookup.has(slug)) {
|
||||||
res.set({
|
res.writeHead(200, {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user