diff --git a/app/server.js b/app/server.js index 13ba886..be338a1 100644 --- a/app/server.js +++ b/app/server.js @@ -1,20 +1,21 @@ -import fs from 'fs'; -import polka from 'polka'; +import { resolve } from 'url'; +import express from 'express'; import compression from 'compression'; import sapper from 'sapper'; import serve from 'serve-static'; import fetch from 'node-fetch'; -import { routes } from './manifest/server.js'; +import { basepath, routes } from './manifest/server.js'; + +const { PORT } = 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}`; + url = resolve(`http://localhost:${PORT}${basepath}/`, url); return fetch(url, opts); }; -// you can also use Express -polka() +express() .use(compression({ threshold: 0 })) - .use(serve('assets')) + .use(basepath, serve('assets')) .use(sapper({ routes })) - .listen(process.env.PORT); \ No newline at end of file + .listen(PORT); \ No newline at end of file diff --git a/app/template.html b/app/template.html index 5dc665a..43e1ef3 100644 --- a/app/template.html +++ b/app/template.html @@ -5,15 +5,11 @@ - - - + %sapper.base% - + + + -
  • blog
  • +
  • blog
  • diff --git a/routes/blog/[slug].html b/routes/blog/[slug].html index 96c4699..da4728b 100644 --- a/routes/blog/[slug].html +++ b/routes/blog/[slug].html @@ -59,7 +59,7 @@ // is called [slug].html const { slug } = params; - return fetch(`/blog/${slug}.json`).then(r => r.json()).then(post => { + return fetch(`blog/${slug}.json`).then(r => r.json()).then(post => { return { post }; }); } diff --git a/routes/blog/_posts.js b/routes/blog/_posts.js index 9e1ac88..3d7efd3 100644 --- a/routes/blog/_posts.js +++ b/routes/blog/_posts.js @@ -14,7 +14,7 @@ const posts = [ html: `

    First, you have to know what Svelte is. Svelte is a UI framework with a bold new idea: rather than providing a library that you write code with (like React or Vue, for example), it's a compiler that turns your components into highly optimized vanilla JavaScript. If you haven't already read the introductory blog post, you should!

    -

    Sapper is a Next.js-style framework (more on that here) built around Svelte. It makes it embarrassingly easy to create extremely high performance web apps. Out of the box, you get:

    +

    Sapper is a Next.js-style framework (more on that here) built around Svelte. It makes it embarrassingly easy to create extremely high performance web apps. Out of the box, you get:

    @@ -32,7 +32,7 @@ }, preload({ params, query }) { - return fetch(`/blog.json`).then(r => r.json()).then(posts => { + return fetch(`blog.json`).then(r => r.json()).then(posts => { return { posts }; }); } diff --git a/routes/index.html b/routes/index.html index 898bb5f..0b5f857 100644 --- a/routes/index.html +++ b/routes/index.html @@ -6,7 +6,7 @@

    Great success!

    - Borat + Borat
    HIGH FIVE!