From c9c5a830071948f7f37b40f239c31748b1630338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Fri, 9 Aug 2024 21:36:18 +0300 Subject: [PATCH] Implement json error pages --- bin/generator.js | 13 +++++++++++-- config-dist.json | 3 ++- config.json | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bin/generator.js b/bin/generator.js index c5d9585..61240ec 100644 --- a/bin/generator.js +++ b/bin/generator.js @@ -67,8 +67,17 @@ async function generator(configFilename, distPath, opt){ // write content to file await _fs.writeFile(_path.join(distPath, templateVars.scheme), content, 'utf8'); - console.log(` |- Page <${templateVars.scheme}>`); + + const jsonContent = { + "status": Number(templateVars.code), + "title": templateVars.title, + "detail": templateVars.message + } + + await _fs.writeFile(_path.join(distPath, templateVars.baseScheme) + '.json', JSON.stringify(jsonContent, null, 4), 'utf8'); + console.log(` |- Page <${templateVars.baseScheme}.json>`); + })); } @@ -131,4 +140,4 @@ _cli.parse(process.argv); // default action (no command provided) if (!process.argv.slice(2).length) { _cli.outputHelp(); -} \ No newline at end of file +} diff --git a/config-dist.json b/config-dist.json index dab23ff..33c4888 100644 --- a/config-dist.json +++ b/config-dist.json @@ -1,10 +1,11 @@ { // Output Filename Scheme - eg. HTTP500.html "scheme": "HTTP%code%.html", + "baseScheme": "HTTP%code%", // Page title (HTML not allowed) "pagetitle": "We've got some trouble | %code% - %title%", // Footer content (HTML Allowed) "footer": null -} \ No newline at end of file +} diff --git a/config.json b/config.json index b709d9f..3b912f8 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,7 @@ { // Output Filename Scheme - eg. HTTP500.html "scheme": "HTTP%code%.html", + "baseScheme": "HTTP%code%", // Page title (HTML not allowed) "pagetitle": "We've got some trouble | %code% - %title%", @@ -10,4 +11,4 @@ // additional vars "myvar" : "Hello World" -} \ No newline at end of file +}