diff --git a/README.md b/README.md index c6c88df4df0f9b38d40d1b4a63a3550ba00a47e6..abb2a5fc7e96503e202abd939f762b7340f34688 100644 --- a/README.md +++ b/README.md @@ -37,27 +37,37 @@ wget https://raw.githubusercontent.com/AndiDittrich/HttpErrorPages/master/dist/p [NGINX](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page) supports custom error-pages using multiple `error_page` directives. -File: `default.conf` +File: [`default.conf`](https://www.nginx.com/resources/wiki/start/topics/examples/full/) -Example - assumes HttpErrorPages are located into `/var/www/ErrorPages/`. +Example - assumes HttpErrorPages are located into `/var/ErrorPages/`. ```nginx -# add one directive for each http status code -error_page 400 /ErrorPages/HTTP400.html; -error_page 401 /ErrorPages/HTTP401.html; -error_page 402 /ErrorPages/HTTP402.html; -error_page 403 /ErrorPages/HTTP403.html; -error_page 404 /ErrorPages/HTTP404.html; -error_page 500 /ErrorPages/HTTP500.html; -error_page 501 /ErrorPages/HTTP501.html; -error_page 502 /ErrorPages/HTTP502.html; -error_page 503 /ErrorPages/HTTP503.html; - -# redirect the virtual ErrorPages path the real path -location /ErrorPages/ { - alias /var/www/ErrorPages/; - internal; -} +server { + listen 80; + server_name localhost; + root /var/www; + index index.html; + + location / { + try_files $uri $uri/ =404; + + # add one directive for each http status code + error_page 400 /ErrorPages/HTTP400.html; + error_page 401 /ErrorPages/HTTP401.html; + error_page 402 /ErrorPages/HTTP402.html; + error_page 403 /ErrorPages/HTTP403.html; + error_page 404 /ErrorPages/HTTP404.html; + error_page 500 /ErrorPages/HTTP500.html; + error_page 501 /ErrorPages/HTTP501.html; + error_page 502 /ErrorPages/HTTP502.html; + error_page 503 /ErrorPages/HTTP503.html; + } + + # redirect the virtual ErrorPages path the real path + location /ErrorPages/ { + alias /var/ErrorPages/; + internal; + } ``` ## expressjs Integration ## @@ -147,22 +157,33 @@ Custom Error-Codes used by e.g. CloudFlare ``` ### Build/Generator ### +* Install packages using npm or yarn and have php in your executable path* Used Naming-Scheme: `HTTP#CODE#.html` (customizable by editing the `config.ini`) To generate the static html pages, run the `generator.php` script: ```shell -php generator.php +npm run generate-php ``` All generated html files are located into the `dist/` directory by default. ### Compile LESS Files ### -To rebuild the LESS files run the **ANT** build script (requires lessc in your path): +To rebuild the LESS files run the : ```shell -ant css +npm run generate-css ``` +### Build all ### + +```shell +npm run generate +``` + + +### Less CSS ### + +Modify the `assets/Layout.less` to make your own design styles (Make sure to run build scripts after editing the files) ### Configuration ### @@ -186,4 +207,4 @@ footer = "Technical Contact: x@example.com" ``` ## License ## -HttpErrorsPages is OpenSource and licensed under the Terms of [The MIT License (X11)](http://opensource.org/licenses/MIT) - your're welcome to contribute \ No newline at end of file +HttpErrorsPages is OpenSource and licensed under the Terms of [The MIT License (X11)](http://opensource.org/licenses/MIT) - your're welcome to contribute diff --git a/generator.php b/generator.php index 05ced2d247df570f9d65de086bbf60af9c53ab01..2b913d10d294e8da2e8ce556342b954c10bdaa01 100644 --- a/generator.php +++ b/generator.php @@ -21,8 +21,25 @@ if (isset($argv[1])){ // load config $config = parse_ini_file($configFilename, false); -// load pages -$pages = require('pages.php'); +//default language +$language = 'en_US'; + +if (isset($argv[2])) { + $language = $argv[2]; +} + +//Internationalization +switch($language) { + case 'pt_BR': + $pages = require('pages-pt_BR.php'); + break; + case 'en_US': + $pages = require('pages-en_US.php'); + break; + default: + $pages = require('pages-en_US.php'); + break; +} // store pages as json data file_put_contents('dist/pages.json', json_encode($pages)); diff --git a/package.json b/package.json index 57c3f06af3ce69565ac84965b96919fa575be75f..d83cf68ebceb3c0b6950efba1644c4e44167e69d 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,11 @@ "name": "http-error-pages", "version": "0.5.2", "description": "Simple HTTP Error Pages for expressjs", + "scripts":{ + "generate-css":"lessc assets/Layout.less assets/Layout.css", + "generate-html":"php generator.php", + "generate": "npm run generate-css && npm run generate-html" + }, "keywords": [ "http", "https", @@ -29,5 +34,8 @@ "license": "MIT", "devDependencies": { "express": "^4.15.2" + }, + "dependencies": { + "less": "^2.7.3" } } diff --git a/pages.php b/pages-en_US.php similarity index 100% rename from pages.php rename to pages-en_US.php diff --git a/pages-pt_BR.php b/pages-pt_BR.php new file mode 100644 index 0000000000000000000000000000000000000000..247ad52f2e3e4f84f4c752dac0f8a391f4bec248 --- /dev/null +++ b/pages-pt_BR.php @@ -0,0 +1,68 @@ + array ( + 'title' => 'Requisição inválida', + 'message' => 'Oops! Não conseguimos processar a requisição.' + ), + '401' => array ( + 'title' => 'Não Autorizado', + 'message' => 'Oops! O recurso requer uma autenticação.' + ), + '403' => array ( + 'title' => 'Acesso Negado', + 'message' => 'Oops! O recurso requer uma autenticação.' + ), + + // http 404 not found + '404' => array ( + 'title' => 'Página Não Encontrada', + 'message'=>'Oops! Não conseguimos encontrar a página que você estava procurando.' + ), + + // internal server error + '500' => array ( + 'title' => 'Webservice Atualmente Não Disponível', + 'message' => "Uma condição inesperada foi encontrada.\nNosso time de serviços está trabalhando para deixar isso online novamente." + ), + + // unknown http method + '501' => array ( + 'title' => 'Não implementado', + 'message' => 'Oops! O Webserver não conseguiu reconhecer o método solicitado' + ), + + // http proxy forward error + '502' => array ( + 'title' => 'Webservice atualmente indisponível', + 'message' => "Nós tivemos alguns problema com o nosso backend. Nosso time de serviços está trabalhando para deixar isso online novamente." + ), + + // webserver service error + '503' => array ( + 'title' => 'Webservice atualmente indisponível', + 'message' => "Nós tivemos alguns problema com o nosso backend. Nosso time de serviços está trabalhando para deixar isso online novamente." + ), + + // CUSTOM ERROR CODES + // ======================================================= + // webserver origin error + '520' => array( + 'title' => 'Origin Error - Host Desconhecido', + 'message' => 'O hostname requisitado não é roteado. Use apenas hostnames para acessar recursos.' + ), + + // webserver down error + '521' => array ( + 'title' => 'Webservice atualmente indisponível', + 'message' => "Nós tivemos alguns problema com o nosso backend. Nosso time de serviços está trabalhando para deixar isso online novamente." + ), + + // maintenance + '533' => array( + 'title' => 'Estamos em manutenção', + 'message' => "O site está offline para manutenção.\nNosso time está trabalhando para reestabelecer o serviço em breve." + ) +);