-
Notifications
You must be signed in to change notification settings - Fork 2
Working with Netlify
skitsanos edited this page Aug 21, 2022
·
4 revisions
If you are using Netlify, here is an example of how to proxy your URL API calls to ArangoDB Microservices.
[build]
base = "."
publish = "./dist"
functions = "netlify-functions/"
[[redirects]]
from = "/api/*"
to = "http://{YOUR_HOSTNAME}:8529/_db/{YOUR_DATABASE}/{YOUR_ENDPOINT}/:splat"
status = 200
force = true
headers = {X-From = "Netlify", X-Api-Key = "some-api-key-string"}
Before deploying it on Netlify, make sure there are two variables replaced:
-
{YOUR_HOSTNAME}
- the hostname where ArangoDb is running -
{YOUR_DATABASE}
- ArangoDB database name where the Foxx service is installed -
{YOUR_ENDPOINT}
- endpoint where your flex services are mounted
Minimal netlify.toml
could look like this:
[[redirects]]
from = "/api/*"
to = "http://localhost:8529/_db/dev/api/:splat"
status = 200
force = true
headers = {X-From = "Netlify", X-Api-Key = "some-api-key-string"}
Notice the X-Api-Key
header that we added in netlify.toml
file above. If you want to add some basic layer of protection for your Foxx Microservices, you can add the following router handler into your index.js
:
const builder = require('./builder/index');
builder.init();
module.context.use((req, res, next) =>
{
const apiKey = req.headers['x-api-key'];
if (!apiKey || apiKey !== 'some-api-key-string')
{
res.throw(400, 'Invalid API key');
}
next();
});
It will check if the API key you've passed to Foxx service is the same one as in your TOML file and will reject the request if the check fails.
Copyright © 2016-2022, Skitsanos™