9
0
mirror of https://github.com/donlon/cloudflare-error-page.git synced 2025-12-21 07:49:24 +00:00

Node ver.

This commit is contained in:
Jun
2025-12-10 13:02:21 +10:30
parent 94c3c4ddbe
commit 744ae19f09
11 changed files with 668 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { render } from '../dist/index.js';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Generate an error page
const errorPage = render({
browser_status: {
status: 'ok',
},
cloudflare_status: {
status: 'error',
status_text: 'Error',
},
host_status: {
status: 'ok',
location: 'example.com',
},
error_source: 'cloudflare',
what_happened: '<p>There is an internal server error on Cloudflare\'s network.</p>',
what_can_i_do: '<p>Please try again in a few minutes.</p>',
});
const outputPath = join(__dirname, 'error.html');
fs.writeFileSync(outputPath, errorPage);
console.log(`Error page generated: ${outputPath}`);
console.log('Open the file in your browser to view it.');

View File

@@ -0,0 +1,32 @@
import { render } from '../dist/index.js';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Test all JSON configs from oringinal examples directory
const testConfigs = [
{ file: '../../examples/default.json', output: 'test-default.html' },
{ file: '../../examples/working.json', output: 'test-working.html' },
{ file: '../../examples/catastrophic.json', output: 'test-catastrophic.html' }
];
testConfigs.forEach(({ file, output }) => {
try {
const configPath = join(__dirname, file);
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
console.log(`Testing: ${file}`);
console.log(`Config keys: ${Object.keys(config).join(', ')}`);
const html = render(config);
const outputPath = join(__dirname, output);
fs.writeFileSync(outputPath, html);
} catch (error) {
console.error(`Something went wrong: ${file}`);
console.error(`Error: ${error.message}\n`);
}
});