mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
699cccbdec | |||
abc317955f | |||
be0d3b9e1f | |||
29fdeef742 |
@ -4,6 +4,12 @@ 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].
|
||||
|
||||
## v1.1.0
|
||||
|
||||
### Added
|
||||
|
||||
- Environment variable `DEFAULT_ERROR_CODE` support in docker image
|
||||
|
||||
## v1.0.1
|
||||
|
||||
### Changed
|
||||
|
2
Makefile
2
Makefile
@ -26,7 +26,7 @@ gen: ## Generate error pages
|
||||
preview: ## Build docker image and start preview
|
||||
$(DOCKER_BIN) build -f ./Dockerfile -t $(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
|
||||
$(DOCKER_BIN) run --rm -i -p 8081:8080 -e "TEMPLATE_NAME=ghost" $(APP_NAME):local
|
||||
|
||||
shell: ## Start shell into container with node
|
||||
$(DC_BIN) run $(DC_RUN_ARGS) app sh
|
||||
|
57
README.md
57
README.md
@ -6,6 +6,7 @@
|
||||
|
||||
[![Build Status][badge_build_status]][link_build_status]
|
||||
[![Image size][badge_size_latest]][link_docker_hub]
|
||||
[![Docker Pulls][badge_docker_pulls]][link_docker_hub]
|
||||
[![License][badge_license]][link_license]
|
||||
|
||||
This repository contains:
|
||||
@ -13,6 +14,8 @@ This repository contains:
|
||||
- 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
|
||||
|
||||
Can be used for [Traefik error pages customization](https://docs.traefik.io/middlewares/errorpages/).
|
||||
|
||||
### Demo
|
||||
|
||||
Generated pages (from the latest release) always [accessible here][link_branch_gh_pages] _(sources)_ and on GitHub pages [here][link_gh_pages].
|
||||
@ -39,8 +42,6 @@ If you want to preview the pages using the Docker image:
|
||||
$ make preview
|
||||
```
|
||||
|
||||
Can be used for [Traefik error pages customization](https://docs.traefik.io/middlewares/errorpages/).
|
||||
|
||||
## Templates
|
||||
|
||||
Name | Preview
|
||||
@ -49,20 +50,21 @@ Can be used for [Traefik error pages customization](https://docs.traefik.io/midd
|
||||
|
||||
## Usage
|
||||
|
||||
Generated error pages in our [docker image][link_docker_hub] permanently located in directory `/opt/html/%THEME_NAME%`.
|
||||
Generated error pages in our [docker image][link_docker_hub] permanently located in directory `/opt/html/%TEMPLATE_NAME%`. `nginx` in a container listen for `8080` (`http`) port.
|
||||
|
||||
#### 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`)_
|
||||
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`)_
|
||||
`DEFAULT_ERROR_CODE` | (`404` by default) Code with passed error code will be used as default (index) page (can be used only with `TEMPLATE_NAME` variable)
|
||||
|
||||
### HTTP server for error pages serving only
|
||||
|
||||
Execute in your shell:
|
||||
|
||||
```bash
|
||||
$ docker run --rm -p "8082:8080" tarampampam/error-pages
|
||||
$ docker run --rm -p "8082:8080" tarampampam/error-pages:1.1.0
|
||||
```
|
||||
|
||||
And open in your browser `http://127.0.0.1:8082/ghost/400.html`.
|
||||
@ -103,7 +105,7 @@ FROM nginx:1.18-alpine
|
||||
COPY --chown=nginx \
|
||||
./nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --chown=nginx \
|
||||
--from=tarampampam/error-pages:1.0.0 \
|
||||
--from=tarampampam/error-pages:1.1.0 \
|
||||
/opt/html/ghost /usr/share/nginx/errorpages/_error-pages
|
||||
```
|
||||
|
||||
@ -111,10 +113,44 @@ COPY --chown=nginx \
|
||||
|
||||
### Custom error pages for [Traefik][link_traefik]
|
||||
|
||||
Simple traefik service configuration for usage in [docker swarm][link_swarm] (**change with your needs**):
|
||||
Simple traefik (tested on `v2.2.1`) service configuration for usage in [docker swarm][link_swarm] (**change with your needs**):
|
||||
|
||||
```yaml
|
||||
# Work in progress
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
error-pages:
|
||||
image: tarampampam/error-pages:1.1.0
|
||||
environment:
|
||||
TEMPLATE_NAME: ghost
|
||||
networks:
|
||||
- traefik-public
|
||||
deploy:
|
||||
placement:
|
||||
constraints:
|
||||
- node.role == worker
|
||||
max_replicas_per_node: 1
|
||||
resources:
|
||||
limits:
|
||||
memory: 32M
|
||||
reservations:
|
||||
memory: 16M
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.docker.network=traefik-public
|
||||
- traefik.http.routers.error-pages-router.rule=HostRegexp(`{host:.+}`)
|
||||
- traefik.http.routers.error-pages-router.tls=true
|
||||
- traefik.http.routers.error-pages-router.priority=10
|
||||
- traefik.http.routers.error-pages-router.entrypoints=https
|
||||
- traefik.http.routers.error-pages-router.middlewares=error-pages-middleware@docker
|
||||
- traefik.http.services.error-pages-service.loadbalancer.server.port=8080
|
||||
- traefik.http.middlewares.error-pages-middleware.errors.status=400-599
|
||||
- traefik.http.middlewares.error-pages-middleware.errors.service=error-pages-service@docker
|
||||
- traefik.http.middlewares.error-pages-middleware.errors.query=/{status}.html
|
||||
|
||||
networks:
|
||||
traefik-public:
|
||||
external: true
|
||||
```
|
||||
|
||||
## Changes log
|
||||
@ -142,6 +178,7 @@ This is open-sourced software licensed under the [MIT License][link_license].
|
||||
[badge_pulls]:https://img.shields.io/github/issues-pr/tarampampam/error-pages.svg?style=flat-square&maxAge=180
|
||||
[badge_license]:https://img.shields.io/github/license/tarampampam/error-pages.svg?longCache=true
|
||||
[badge_size_latest]:https://img.shields.io/docker/image-size/tarampampam/error-pages/latest?maxAge=30
|
||||
[badge_docker_pulls]:https://img.shields.io/docker/pulls/tarampampam/error-pages.svg
|
||||
[link_releases]:https://github.com/tarampampam/error-pages/releases
|
||||
[link_commits]:https://github.com/tarampampam/error-pages/commits
|
||||
[link_changes_log]:https://github.com/tarampampam/error-pages/blob/master/CHANGELOG.md
|
||||
|
@ -2,6 +2,7 @@
|
||||
set -e
|
||||
|
||||
TEMPLATE_NAME=${TEMPLATE_NAME:-} # string|empty
|
||||
DEFAULT_ERROR_CODE=${DEFAULT_ERROR_CODE:-404} # numeric
|
||||
|
||||
if [ -n "$TEMPLATE_NAME" ]; then
|
||||
echo "$0: set pages for template '$TEMPLATE_NAME' as default (make accessible in root directory)";
|
||||
@ -11,6 +12,14 @@ if [ -n "$TEMPLATE_NAME" ]; then
|
||||
fi;
|
||||
|
||||
ln -f -s "/opt/html/$TEMPLATE_NAME/"* /opt/html;
|
||||
|
||||
if [ -L "/opt/html/$DEFAULT_ERROR_CODE.html" ]; then
|
||||
echo "$0: set page with error code '$DEFAULT_ERROR_CODE' as default (index) page";
|
||||
|
||||
cp -f "/opt/html/$DEFAULT_ERROR_CODE.html" /opt/html/index.html;
|
||||
else
|
||||
(>&2 echo "$0: cannot set page with error code '$DEFAULT_ERROR_CODE' as default (index) page!");
|
||||
fi;
|
||||
fi;
|
||||
|
||||
exec "$@"
|
||||
|
Reference in New Issue
Block a user