Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Aug 26, 2023
1 parent 3f325f5 commit ad15a7f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/api/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
12 changes: 12 additions & 0 deletions src/api/app.controller.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
13 changes: 13 additions & 0 deletions src/api/app.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
8 changes: 8 additions & 0 deletions src/api/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
41 changes: 41 additions & 0 deletions src/api/main.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit ad15a7f

Please sign in to comment.