Coder Social home page Coder Social logo

backend's Introduction

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

backend's People

Contributors

romeq avatar roytakanen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

romeq samip5

backend's Issues

Rate limit errors aren't in JSON

Rate limit error messages are sent as plain-text bodies, which is not in accordance with the API specification. The messages should be amended to contain a title and a message, as with other errors.

Current behaviour:

$ curl -d '{"paste": "Liitteen sisältö", "title": "Testiliite"}' https://api.pastebin.fi/pastes/
Liian monta liitettä on luotu IP-osoitteestasi. Kokeile myöhemmin uudelleen.⏎

Expected behaviour:

$ curl -d '{"paste": "Liitteen sisältö", "title": "Testiliite"}' https://api.pastebin.fi/pastes/
{"title": "Liian monta liitettä lyhyessä ajassa", "message": "Liian monta liitettä on luotu IP-osoitteestasi. Kokeile myöhemmin uudelleen."}⏎

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.