mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-14 11:14:39 +00:00
make basepath-friendly
This commit is contained in:
@@ -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);
|
||||
.listen(PORT);
|
||||
Reference in New Issue
Block a user