diff --git a/src/api/app.controller.spec.ts b/src/api/app.controller.spec.ts new file mode 100644 index 000000000..d22f3890a --- /dev/null +++ b/src/api/app.controller.spec.ts @@ -0,0 +1,22 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; + +describe('AppController', () => { + let appController: AppController; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [AppController], + providers: [AppService], + }).compile(); + + appController = app.get(AppController); + }); + + describe('root', () => { + it('should return "Hello World!"', () => { + expect(appController.getHello()).toBe('Hello World!'); + }); + }); +}); diff --git a/src/api/app.controller.ts b/src/api/app.controller.ts new file mode 100644 index 000000000..cce879ee6 --- /dev/null +++ b/src/api/app.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { AppService } from './app.service'; + +@Controller() +export class AppController { + constructor(private readonly appService: AppService) {} + + @Get() + getHello(): string { + return this.appService.getHello(); + } +} diff --git a/src/api/app.module.ts b/src/api/app.module.ts new file mode 100644 index 000000000..729a45210 --- /dev/null +++ b/src/api/app.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common'; +import { AppController } from './app.controller'; +import { PassportModule } from '@nestjs/passport'; +import { AppService } from './app.service'; + +@Module({ + imports: [ + PassportModule.register({ session: true }), + ], + controllers: [AppController], + providers: [AppService], +}) +export class AppModule {} diff --git a/src/api/app.service.ts b/src/api/app.service.ts new file mode 100644 index 000000000..927d7cca0 --- /dev/null +++ b/src/api/app.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class AppService { + getHello(): string { + return 'Hello World!'; + } +} diff --git a/src/api/main.ts b/src/api/main.ts index e69de29bb..53e678780 100644 --- a/src/api/main.ts +++ b/src/api/main.ts @@ -0,0 +1,41 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; +import config from '../config'; +import Logger from '../structures/Logger'; +import { PrismaSessionStore } from '@quixo3/prisma-session-store'; +import { PrismaClient } from '@prisma/client'; +import session from 'express-session'; +import passport from 'passport'; + + +async function bootstrap() { + const app = await NestFactory.create(AppModule, { + logger: new Logger(), + }); + app.setGlobalPrefix("/api"); + app.use( + session({ + secret: 'q7a1s4r41fs84s8ws7e7dnsd', + resave: false, + saveUninitialized: false, + cookie: { + maxAge: 60000 * 60 * 24, + }, + store: new PrismaSessionStore(new PrismaClient(), { + checkPeriod: 2 * 60 * 1000, //ms + dbRecordIdIsSessionId: true, + dbRecordIdFunction: undefined, + }) + }), + ); + app.enableCors({ + origin: config.dashboard.website, + credentials: true, + }); + app.use(passport.initialize()); + app.use(passport.session()); + await app.listen(config.dashboard.port); + new Logger().success(`Api is running on port ${config.dashboard.port}`); +} + +export { bootstrap }; \ No newline at end of file