Browse Source

Use relative paths for html resources, to allow reverse proxying (#175)

Use relative paths for html resources, to allow reverse proxying
pull/163/head^2
Cian Butler 6 years ago
committed by GitHub
parent
commit
7b82c456c7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/server/server.ts

15
src/server/server.ts

@ -29,7 +29,8 @@ export default function createServer(
const html = (
req: express.Request,
res: express.Response
): express.Response =>
): express.Response => {
const resourcePath = /^\/ssh\//.test(req.url) ? '../' : '';
res.send(`<!doctype html>
<html lang="en">
<head>
@ -37,7 +38,7 @@ export default function createServer(
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>${title}</title>
<link rel="stylesheet" href="${basePath}/public/index.css" />
<link rel="stylesheet" href="${resourcePath}public/index.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
</head>
<body>
@ -54,9 +55,10 @@ export default function createServer(
<textarea class="editor"></textarea>
</div>
<div id="terminal"></div>
<script src="${basePath}/public/index.js"></script>
<script src="${resourcePath}public/index.js"></script>
</body>
</html>`);
}
const app = express();
app
@ -65,12 +67,7 @@ export default function createServer(
.use(favicon(path.join(distDir, 'favicon.ico')))
.use(`${basePath}/public`, express.static(distDir))
.use((req, res, next) => {
if (
req.url.substr(-1) === '/' &&
req.url.length > 1 &&
!/\?[^]*\//.test(req.url)
)
res.redirect(301, req.url.slice(0, -1));
if (req.url === basePath) res.redirect(301, req.url + '/');
else next();
});

Loading…
Cancel
Save