Support for users and authentication [backend].

This commit is contained in:
Fabio Manganiello 2025-03-04 21:29:05 +01:00
parent 533ebe960f
commit c4e0c67e34
Signed by: blacklight
GPG key ID: D90FBA7F76362774
35 changed files with 1329 additions and 111 deletions

56
src/App.ts Normal file
View file

@ -0,0 +1,56 @@
import cors from 'cors';
import express from 'express';
import bodyParser from 'body-parser';
import { useGlobals } from './globals';
import Routes from './routes';
class App {
private readonly app: express.Express;
private readonly address: string;
private readonly port: number;
private constructor({
app,
address,
port,
routes,
}: any) {
useGlobals();
$db.sync().then(() => {
$repos.userRoles.init();
$repos.users.syncAdminUser();
})
this.app = app;
this.address = address;
this.port = port;
app.use(cors());
app.use(bodyParser.json());
app.use(express.static('frontend/dist'));
routes.register(app)
}
public static fromEnv(): App {
const address = process.env.BACKEND_ADDRESS || '127.0.0.1';
const port = new Number(process.env.BACKEND_PORT || 3000).valueOf();
const app = express();
const routes = new Routes();
return new App({
app,
address,
port,
routes,
});
}
public listen(): void {
this.app.listen(this.port, this.address, () => {
console.log(`Server is running on port ${this.address}:${this.port}`);
});
}
}
export default App;