This is a simple/sample proxying API for TMDB with Fastify.
This repository is only for study purposes. Must not be used in production.
TMDB Api works with two variables across requests, they are:
api_key
: for accessing resources;session_id
: to authenticate the user when required.
In a regular web application, you don't want to expose your api_key
or even the session_id
as a regular text on local storage. This is the main reason to use this proxy.
- It will keep your
api_key
in an environment variable and add to proxied requests as a authorization header; - It will convert the
session_id
to anHttpOnly
cookie and share to client, but when proxy the request it will usesession_id
as a query string parameter.
Copy the .env.example
file to .env.development
file. Fill it with API_KEY
and COOKIE_SECRET
.
Run npm run start
command. It will start listening on 0.0.0.0:8080
, call it with any endpoint from TMDB Api and see the magic.
You can use the docker-compose.yaml
file to build and run the container. After, it will start listening on localhost:8080
, call it with any endpoint from TMDB Api and see the magic.
You may use the docker commands instead docker-compose.yaml
:
- Build:
docker build -t tmdb-proxy-api -f ./Dockerfile.dev .
; - Run:
docker run -d -p 8080:8080 -v /usr/app/node_modules -v $(pwd):/usr/app --env-file .env.development tmdb-proxy-api
; - After running, you may see it's running with
docker ps
command.
Copy the .env.example
file to .env.test
file. Fill it with API_KEY
and COOKIE_SECRET
. Then, run npm run test
to watch all tests or npm run test:once
to run once.
This repository is only for study purposes. Must not be used in production. But, if you want to try... Copy the .env.example
file to .env.production
file. Fill it with API_KEY
and COOKIE_SECRET
. You can use npm run build
to build all .js
files and then npm run launch
to start listening.
You can do it with docker:
- Build:
docker build -t tmdb-proxy-api -f ./Dockerfile.prod .
; - Run:
docker run -d -p 8080:8080 -v /usr/app/node_modules -v $(pwd):/usr/app --env-file .env.production tmdb-proxy-api
; - After running, you may see it's running with
docker ps
command.