The AOC Framework
github logodiscord logo

BACKEND

Introduction #

The backend (server) is a program that runs on node.js (or similar) written in TypeScript.

It uses express as an HTTP library, socket.io as a WebSockets library, and mikro-orm as an ORM library.

Example #

The minimal necessary index.ts file for your server project is:

import 'reflect-metadata';
import { AocServer } from '@atlantis-of-code/aoc-server';
require('express-async-errors');

const aocServer = new AocServer();
aocServer.listen();

And in this other example (Quest), we expand its use a bit:

  • We register objects to be sent to the report generator and to be used in pug files
  • We define a custom router for file upload and download with our customized logic
import 'reflect-metadata';
import { AocReport, AocServer } from '@atlantis-of-code/aoc-server';
import Big from 'big.js';
import * as dateFns from 'date-fns';
import { FileRouter } from './routers/file.router';

AocReport.globalLocals.dateFns = dateFns;
AocReport.globalLocals.numberFormat = new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format;
AocReport.globalLocals.Big = Big;

require('express-async-errors');

const aocServer = new AocServer({
  customRouters: [
    {
      path: '/file',
      router: new FileRouter().router,
      checkAuth: true
    }
  ]
});

aocServer.listen();

See the full example at quest-server/src/index.ts

Api #

Complete definition in the API.

Please note, browse Issues and Discussions in Github for more information

© 2024 Atlantis of Code. All rights reserved.
All trademarks are the property of their respective owners.