Skip to content

Commit

Permalink
Merge pull request #26 from magicpages/develop
Browse files Browse the repository at this point in the history
v1.5.0
  • Loading branch information
betschki authored Jul 21, 2024
2 parents c69de66 + 55ada0f commit fe931d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express, { Response } from 'express';
import httpProxy from 'http-proxy';
import dotenv from 'dotenv';
import fetch, { Headers as FetchHeaders, RequestInit } from 'node-fetch';
import { deleteStorageZoneFile, getPullZoneName, listStorageZoneFiles, FileDetail } from './util.js';
import { deleteStorageZoneFile, getPullZoneName, listStorageZoneFiles, FileDetail, errorHtml } from './util.js';

dotenv.config();

Expand Down Expand Up @@ -40,9 +40,10 @@ proxy.on('proxyRes', async (proxyRes, req, res) => {
});
});

// This error handler replicates the error page from Ghost
proxy.on('error', (err, req, res) => {
console.error('Proxy error:', err);
(res as Response).status(500).send('Proxy error');
console.error("Error during proxy operation:", err);
(res as Response).status(503).send(errorHtml);
});

app.use((req, res) => {
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export const deleteStorageZoneFile = async (storageZoneName: string, path: strin
return await response.json();
};

// This is the minified maintenance page HTML from Ghost
// @See: https://github.com/TryGhost/Ghost/blob/v5.88.1/ghost/core/core/server/views/maintenance.html
export const errorHtml = `<!doctypehtml><meta charset=utf-8><meta content="IE=edge"http-equiv=X-UA-Compatible><meta content="width=device-width,initial-scale=1"name=viewport><title>We'll be right back</title><style>*{box-sizing:border-box}html{font-size:62.5%;background:#f1f2f3;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}body{display:flex;flex-direction:column;justify-content:center;align-items:center;height:100vh;width:100vw;margin:0;padding:4vmin;color:#15171a;font-size:2rem;line-height:1.4em;font-family:sans-serif;background:#f1f2f3;scroll-behavior:smooth;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}::selection{text-shadow:none;background:#cbeafb}.content{display:flex;flex-direction:column;justify-content:center;max-width:500px;min-height:360px;margin:0 0 4vmin;padding:40px;text-align:center;background:#fff;border-radius:20px;box-shadow:0 50px 100px -20px rgb(50 50 93 / 8%),0 30px 60px -30px rgb(0 0 0 / 13%),0 10px 20px -10px rgb(0 0 0 / 8%)}h1{margin:0 0 .3em;font-size:4rem;line-height:1em;font-weight:700;letter-spacing:-.02em}p{margin:0;opacity:.7;font-weight:400}img{display:block;margin:0 auto 40px}@media (max-width:500px){body{font-size:1.8rem}h1{font-size:3.4rem}}</style><div class=content><h1>We'll be right back.</h1><p>We're busy updating our site to give you the best experience, and will be back soon.</div>`;

export interface FileDetail {
Guid: string,
StorageZoneName: string,
Expand Down

0 comments on commit fe931d4

Please sign in to comment.