mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
Improve repository
This commit is contained in:
parent
10ba04b263
commit
5e29c30c23
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -26,7 +26,7 @@ jobs:
|
|||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: ./bin/generator.js -c ./configuration.json -o ./out
|
run: ./bin/generator.js -c ./config.json -o ./out
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -30,7 +30,7 @@ jobs: # Docs: <https://git.io/JvxXE>
|
|||||||
run: yarn install
|
run: yarn install
|
||||||
|
|
||||||
- name: Run generator
|
- name: Run generator
|
||||||
run: ./bin/generator.js -c ./configuration.json -o ./out
|
run: ./bin/generator.js -c ./config.json -o ./out
|
||||||
|
|
||||||
- name: Test file creation
|
- name: Test file creation
|
||||||
run: test -f ./out/ghost/404.html
|
run: test -f ./out/ghost/404.html
|
||||||
|
18
CHANGELOG.md
18
CHANGELOG.md
@ -4,6 +4,24 @@ All notable changes to this package will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
|
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
|
||||||
|
|
||||||
|
## UNRELEASED
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `configuration.json` renamed to `config.json`
|
||||||
|
- Makefile contains new targets (`install`, `gen`, `preview`)
|
||||||
|
- Generator logging messages
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `docker-compose` for development
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Readme file content [#1]
|
||||||
|
|
||||||
|
[#1]:https://github.com/tarampampam/error-pages/issues/1
|
||||||
|
|
||||||
## v1.0.0
|
## v1.0.0
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -7,7 +7,7 @@ COPY . .
|
|||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& yarn install --frozen-lockfile \
|
&& yarn install --frozen-lockfile \
|
||||||
&& ./bin/generator.js -c ./configuration.json -o ./out
|
&& ./bin/generator.js -c ./config.json -o ./out
|
||||||
|
|
||||||
# Image page: <https://hub.docker.com/_/nginx>
|
# Image page: <https://hub.docker.com/_/nginx>
|
||||||
FROM nginx:1.18-alpine
|
FROM nginx:1.18-alpine
|
||||||
|
17
Makefile
17
Makefile
@ -5,17 +5,28 @@
|
|||||||
SHELL = /bin/sh
|
SHELL = /bin/sh
|
||||||
|
|
||||||
DOCKER_BIN = $(shell command -v docker 2> /dev/null)
|
DOCKER_BIN = $(shell command -v docker 2> /dev/null)
|
||||||
|
DC_BIN = $(shell command -v docker-compose 2> /dev/null)
|
||||||
|
|
||||||
|
DC_RUN_ARGS = --rm --user "$(shell id -u):$(shell id -g)"
|
||||||
APP_NAME = $(notdir $(CURDIR))
|
APP_NAME = $(notdir $(CURDIR))
|
||||||
|
|
||||||
|
.PHONY : help install gen preview
|
||||||
.DEFAULT_GOAL : help
|
.DEFAULT_GOAL : help
|
||||||
|
|
||||||
help: ## Show this help
|
help: ## Show this help
|
||||||
@printf "\033[33m%s:\033[0m\n" 'Available commands'
|
@printf "\033[33m%s:\033[0m\n" 'Available commands'
|
||||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||||
|
|
||||||
image: ## Build docker image
|
install: ## Install all dependencies
|
||||||
|
$(DC_BIN) run $(DC_RUN_ARGS) app yarn install
|
||||||
|
|
||||||
|
gen: ## Generate error pages
|
||||||
|
$(DC_BIN) run $(DC_RUN_ARGS) app nodejs ./bin/generator.js -c ./config.json -o ./out
|
||||||
|
|
||||||
|
preview: ## Build docker image and start preview
|
||||||
$(DOCKER_BIN) build -f ./Dockerfile -t $(APP_NAME):local .
|
$(DOCKER_BIN) build -f ./Dockerfile -t $(APP_NAME):local .
|
||||||
@printf "\n \e[30;42m %s \033[0m\n\n" 'Now you can use image like `docker run --rm -p 8080:8080 $(APP_NAME):local ...`'
|
@printf "\n \e[30;42m %s \033[0m\n\n" 'Now open in your favorite browser <http://127.0.0.1:8081> and press CTRL+C for stopping'
|
||||||
|
$(DOCKER_BIN) run --rm -i -p 8081:8080 $(APP_NAME):local
|
||||||
|
|
||||||
shell: ## Start shell into container with node
|
shell: ## Start shell into container with node
|
||||||
$(DOCKER_BIN) run --rm -ti -v "$(shell pwd):/src:rw" -w "/src" --user "$(shell id -u):$(shell id -g)" node:12.16.2-alpine sh
|
$(DC_BIN) run $(DC_RUN_ARGS) app sh
|
||||||
|
117
README.md
117
README.md
@ -2,64 +2,110 @@
|
|||||||
<img src="https://hsto.org/webt/rg/ys/c3/rgysc33oc7jiufdzmwrkohpmef8.png" width="94" alt="" />
|
<img src="https://hsto.org/webt/rg/ys/c3/rgysc33oc7jiufdzmwrkohpmef8.png" width="94" alt="" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Static error pages in a Docker container
|
# HTTP's error pages in :whale: image
|
||||||
|
|
||||||
[![Build Status][badge_build_status]][link_build_status]
|
[![Build Status][badge_build_status]][link_build_status]
|
||||||
|
[![Image size][badge_size_latest]][link_docker_hub]
|
||||||
[![License][badge_license]][link_license]
|
[![License][badge_license]][link_license]
|
||||||
|
|
||||||
This repository contains a very simple generator for server error pages _(like `404: Not found`)_ and ready docker image with web server for error pages serving.
|
This repository contains:
|
||||||
|
|
||||||
Generator ([`bin/generator.js`](./bin/generator.js)) allows you:
|
- A very simple [generator](./bin/generator.js) _(`nodejs`)_ for HTTP error pages _(like `404: Not found`)_ with different templates supports
|
||||||
|
- Dockerfile for [docker image][link_docker_hub] with generated pages and `nginx` as web server
|
||||||
|
|
||||||
- Use different templates (section `templates` in configuration file)
|
## Development
|
||||||
- Generate pages with arbitrary content according to a specific template
|
|
||||||
|
> For project development we use `docker-ce` + `docker-compose`. Make sure you have them installed.
|
||||||
|
|
||||||
|
Install `nodejs` dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make install
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to generate error pages on your machine _(after that look into output directory)_:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make gen
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to preview the pages using the Docker image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make preview
|
||||||
|
```
|
||||||
|
|
||||||
Can be used for [Traefik error pages customization](https://docs.traefik.io/middlewares/errorpages/).
|
Can be used for [Traefik error pages customization](https://docs.traefik.io/middlewares/errorpages/).
|
||||||
|
|
||||||
### Usage
|
## Usage
|
||||||
|
|
||||||
Just execute (installed `nodejs` is required):
|
Generated error pages in our [docker image][link_docker_hub] permanently located in directory `/opt/html/%THEME_NAME%`.
|
||||||
|
|
||||||
|
#### Supported environment variables
|
||||||
|
|
||||||
|
Name | Description
|
||||||
|
--------------- | -----------
|
||||||
|
`TEMPLATE_NAME` | "default" pages template _(allows to use error pages without passing theme name in URL - `http://127.0.0.1/500.html` instead `http://127.0.0.1/ghost/500.html`)_
|
||||||
|
|
||||||
|
### HTTP server for error pages serving only
|
||||||
|
|
||||||
|
Execute in your shell:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ bin/generator.js -c ./configuration.json -o ./out
|
$ docker run --rm -p "8082:8080" tarampampam/error-pages
|
||||||
```
|
```
|
||||||
|
|
||||||
And watch into `./out` directory:
|
And open in your browser `http://127.0.0.1:8082/ghost/400.html`.
|
||||||
|
|
||||||
```text
|
### Custom error pages for [nginx][link_nginx]
|
||||||
./out
|
|
||||||
└── ghost
|
|
||||||
├── 400.html
|
|
||||||
├── 401.html
|
|
||||||
├── 403.html
|
|
||||||
├── 404.html
|
|
||||||
├── ...
|
|
||||||
└── 505.html
|
|
||||||
```
|
|
||||||
|
|
||||||
Default configuration can be found in [`configuration.json`](./configuration.json) file.
|
You can build your own docker image with `nginx` and our error pages:
|
||||||
|
|
||||||
### Docker
|
|
||||||
|
|
||||||
[![Image size][badge_size_latest]][link_docker_build]
|
|
||||||
|
|
||||||
Start image (`nginx` inside):
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker run --rm -p "8080:8080" tarampampam/error-pages:1.0.0
|
# File `./nginx.conf`
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
error_page 401 /_error-pages/401.html;
|
||||||
|
error_page 403 /_error-pages/403.html;
|
||||||
|
error_page 404 /_error-pages/404.html;
|
||||||
|
error_page 500 /_error-pages/500.html;
|
||||||
|
error_page 502 /_error-pages/502.html;
|
||||||
|
error_page 503 /_error-pages/503.html;
|
||||||
|
|
||||||
|
location ^~ /_error-pages/ {
|
||||||
|
internal;
|
||||||
|
root /usr/share/nginx/errorpages;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And open in your browser `http://127.0.0.1:8080/ghost/400.html`. Additionally, you can set "default" pages theme by passing `TEMPLATE_NAME` environment variable (eg.: `-e "TEMPLATE_NAME=ghost"`) - in this case all error pages will be accessible in root directory (eg.: `http://127.0.0.1:8080/400.html`).
|
|
||||||
|
|
||||||
Also you can use generated error pages in your own docker images:
|
|
||||||
|
|
||||||
```dockerfile
|
```dockerfile
|
||||||
FROM nginx:1.18-alpine
|
FROM nginx:1.18-alpine
|
||||||
|
|
||||||
COPY --from=tarampampam/error-pages:1.0.0 /opt/html/ghost /usr/share/nginx/html/error-pages
|
COPY --chown=nginx \
|
||||||
|
./nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --chown=nginx \
|
||||||
|
--from=tarampampam/error-pages:1.0.0 \
|
||||||
|
/opt/html/ghost /usr/share/nginx/errorpages/_error-pages
|
||||||
```
|
```
|
||||||
|
|
||||||
> [`error_page` for `nginx` configuration](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page)
|
> More info about `error_page` directive can be [found here](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
|
||||||
|
|
||||||
|
### Custom error pages for [Traefik][link_traefik]
|
||||||
|
|
||||||
|
Simple traefik service configuration for usage in [docker swarm][link_swarm] (**change with your needs**):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Work in progress
|
||||||
|
```
|
||||||
|
|
||||||
## Changes log
|
## Changes log
|
||||||
|
|
||||||
@ -94,4 +140,7 @@ This is open-sourced software licensed under the [MIT License][link_license].
|
|||||||
[link_build_status]:https://travis-ci.org/tarampampam/error-pages
|
[link_build_status]:https://travis-ci.org/tarampampam/error-pages
|
||||||
[link_create_issue]:https://github.com/tarampampam/error-pages/issues/new
|
[link_create_issue]:https://github.com/tarampampam/error-pages/issues/new
|
||||||
[link_license]:https://github.com/tarampampam/error-pages/blob/master/LICENSE
|
[link_license]:https://github.com/tarampampam/error-pages/blob/master/LICENSE
|
||||||
[link_docker_build]:https://hub.docker.com/r/tarampampam/error-pages/
|
[link_docker_hub]:https://hub.docker.com/r/tarampampam/error-pages/
|
||||||
|
[link_nginx]:http://nginx.org/
|
||||||
|
[link_traefik]:https://docs.traefik.io/
|
||||||
|
[link_swarm]:https://docs.docker.com/engine/swarm/
|
||||||
|
@ -46,7 +46,9 @@ try {
|
|||||||
|
|
||||||
// Loop over all pages
|
// Loop over all pages
|
||||||
configContent.pages.forEach((pageConfig) => {
|
configContent.pages.forEach((pageConfig) => {
|
||||||
console.info(`Page with code ${pageConfig.code} generation...`);
|
let outPath = path.join(templateOutDir, `${pageConfig.code}.${configContent.output.file_extension}`);
|
||||||
|
|
||||||
|
console.info(` [${templateConfig.name}:${pageConfig.code}] Output: ${outPath}`);
|
||||||
|
|
||||||
// Make replaces
|
// Make replaces
|
||||||
let result = layoutContent
|
let result = layoutContent
|
||||||
@ -55,7 +57,7 @@ try {
|
|||||||
.replace(/{{\s?description\s?}}/g, pageConfig.description);
|
.replace(/{{\s?description\s?}}/g, pageConfig.description);
|
||||||
|
|
||||||
// And write into result file
|
// And write into result file
|
||||||
fs.writeFileSync(path.join(templateOutDir, `${pageConfig.code}.${configContent.output.file_extension}`), result, {
|
fs.writeFileSync(outPath, result, {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
flag: "w+",
|
flag: "w+",
|
||||||
mode: 0o644
|
mode: 0o644
|
||||||
|
17
docker-compose.yml
Normal file
17
docker-compose.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
version: '3.2'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
tmp-data:
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: node:12.16.2-alpine # Image page: <https://hub.docker.com/_/node>
|
||||||
|
working_dir: /src
|
||||||
|
environment:
|
||||||
|
HOME: /tmp
|
||||||
|
PS1: '\[\033[1;32m\]\[\033[1;36m\][\u@docker] \[\033[1;34m\]\w\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'
|
||||||
|
volumes:
|
||||||
|
- /etc/passwd:/etc/passwd:ro
|
||||||
|
- /etc/group:/etc/group:ro
|
||||||
|
- .:/src:cached
|
||||||
|
- tmp-data:/tmp:cached
|
Loading…
x
Reference in New Issue
Block a user