Skip to content

pastebin-fi/backend

pastebin.fi API

7d uptime badge 7d response time badge health badge (up or down)

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.

Deployment

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).

Stack

Backend

  • 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).

cors

// TODO: create a table of env variables

To enable cors you have to set two env variables:

Example

ENABLE_CORS=true
ALLOWED_CORS_ORIGINS=https://pastebin.fi,http://localhost:3000

Setup

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).

Without Docker

First install required packages with npm install.

You need two terminals for development:

  1. npx tsc -w (this watches the code and recompiles it on every change to ./target dir)
  2. 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).

With Docker

docker-compose.yml contains an example configuration. The configuration variables below work also as environment variables.

Configuration variables

see .env.example