I've been playing with OpenFaaS recently and it's a very accessable
way to starting building cloud first services. I wanted to see what I
could cram in there, so I built a few templates that would let me host
a static site. One that is just html, and another than can be built
with something like
Then add a
Then add a
template/static/Dockerfile to do the build:
Serving at root
Setting up the
This will proxy
/function/* to the OpenFaaS
gateway, and everything else it will (internally) rewrite to
/function/static/, which will get forwarded our static handler. So
when you deploy the function make sure you name it that!
First we need to create our
First we need to create a
node_modules, my least favorite thing in the world, needs to get
excluded, so lets create
must be the same as the
Then we add the
Dockerfile to build everything:
First we will create the function itself, and then populate it using
npx create-react-app testappreact. This will write it into the "handler"
We will also remove the
.git repo that
create-react-app sets up.
I recommend using relative links, by adding
"homepage": "./" in the
Then we can build and deploy using
And visit your server to see what you see!
Testing Vue app
Just for fun, lets make it build a vue app.
In order to get vue apps to have relative paths, you need to create a
vue.config.js file to set it:
vue builds in the
dist directory, we need to modify the
build script inside of
package.json to rename the file after it's
Then, we can build and deploy:
It's a little hacky but it seems to work alright!