This is the API for pastebin.fi. The frontend can be found here.
Documentation for the API can be viewed at api.pastebin.fi/docs. The openapi spec is loaded from openapi.json.
Docker image is automatically built to github content registry from master branch. The same image is also automatically pulled with watchtower to the server (polling interval is 10 seconds).
- Node.JS (version 18)
- MongoDB (mongoose)
- Express
- Docker (not required for development)
The server stores everything to MongoDB. This project utilizes MongoDB's full text search to provide a way to query information from the server.
S3 has been tried as a storage but it had following problems:
- Wasabi had some hiccups from time to time (requests did not finish), but this could be caused by the free trial.
- I had no easy to provide full text search to paste content
Creating & viewing a paste looks like this (currently the whole LangAPI implementation is missing).
// TODO: create a table of env variables
To enable cors you have to set two env variables:
- ENABLE_CORS=true or false (make sure that everything is lower case)
- ALLOWED_CORS_ORIGINS=https://siteyouwanttoallowapiaccess.com (this takes urls separated by commas (no whitespaces allowed), you cannot use * since it does not work with allow credentials). For more information, see: https://www.npmjs.com/package/cors#configuration-options (origin).
Example
ENABLE_CORS=true
ALLOWED_CORS_ORIGINS=https://pastebin.fi,http://localhost:3000
First of all, you should setup the environment variables (see here). I would recommend to copy the .env.example
file to .env
(command is cp .env.example .env
).
First install required packages with npm install
.
You need two terminals for development:
npx tsc -w
(this watches the code and recompiles it on every change to./target
dir)nodemon app.js
(this command must be ran inside./target
dir; you might need to copy the openapi.json file to./target
dir also)
Since the project uses typescript you cannot just start the project with node .
, but have to use npx tsc app
(accept the typescript install prompt if present).
docker-compose.yml
contains an example configuration. The configuration variables below work also as environment variables.
see .env.example