An nginx image for a Single Page App, with clear url and push state friendly by default.
2.3K
A docker base image for a Single Page App (eg. React), within nginx server, clear url, push state friendly by default.
Use the minimalist Nginx image based on Alpine linux (~6 MB).
There are two ways to kick off:
Link your app with this volume -v /your/webapp:/app.
docker run -d --name myapp -p 3000:80 -v /your/webapp:/app 36node/nginx-spa
Strongly suggest you follow this way
FROM 36node/nginx-spa:latest
ENV DEBUG=off
## Suppose your app is in the dist directory.
COPY ./dist /app
Then just publish your images, and run the container from it.
docker run -d -p 80:80 your_image
Take a look at todoMVC examples for more details.
This is a useful feature.
Some times you will need to start App with different env, here comes the runtime env. Just set some environments in your container. It will use envsubst to replace all env placeholder in files ".*.(js|css|html|json|map)".
Take a look at examples/todoMVC/dist/index.html
<script>
(function (){
console.log("${APP_GREETINGS}");
}());
</script>
${APP_GREETINGS} will be gracefully replaced with real runtime env when you start the Web App container.
Try to build the examples/todoMVC image, and run it with some env.
docker run -e APP_GREETINGS="XXXXXX" -d -p 3000:80 todomvc
This image has following preset env.
(172.17.0.1)|(192.168.0.25).note: we suggest you call api with a full url with domain, make your api server independently. But we need to take care of cross domain and https issues.
If your app calls api without domain, and not deploy behind a Well Structured haproxy(or other forward proxy), you can turn on this option.
API_PLACEHOLDER="/api/v1"
API_GATEWAY="http://api.your.domain"
Then all url match /api/v1 will redirect to http://api.your.domain. Please
notice that the /api/v1 is stripped.
In case you need more gateway, you can use another 5 entries API_GATEWAY_1 ~ API_GATEWAY_5, along with API_PLACEHOLDER_1 ~ API_PLACEHOLDER_5.
Suppose you have a domain
www.books.com
You have two apps Computer and Math, want put them under the same domain.
http://www.books.com/computer
http://www.books.com/math
For App computer, setting
APP_BASENAME=/computer
You also need to take care about this path prefix in your APP. Like react router(3.x), it could take a prefix option. We strongly suggest to use the same envrionment in your source code. So this image will take care of it for you. For example, in your router.js file:
import useBasename from "history/lib/useBasename";
import { browserHistory } from "react-router";
export const myHistory = useBasename(() => browserHistory)({
basename: `/${APP_BASENAME}`
});
Turn on white list mode by setting env WHITE_LIST="on", then only allow users from ${WHITE_LIST_IP} list to visit this Web App.
Content type
Image
Digest
Size
9.3 MB
Last updated
over 5 years ago
docker pull 36node/nginx-spa