feat(frontend): setup

This commit is contained in:
Julian Tölle 2020-01-26 19:07:15 +01:00
parent db62d5d908
commit f14eda16ac
33 changed files with 15076 additions and 22 deletions

View file

@ -3,13 +3,15 @@ import { ConfigModule } from "@nestjs/config";
import { AuthenticationModule } from "./authentication/authentication.module";
import { DatabaseModule } from "./database/database.module";
import { ConnectionsModule } from "./connections/connections.module";
import { FrontendModule } from './frontend/frontend.module';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
DatabaseModule,
AuthenticationModule,
ConnectionsModule
ConnectionsModule,
FrontendModule
]
})
export class AppModule {}

View file

@ -1,6 +1,6 @@
import { Module } from "@nestjs/common";
import { JwtStrategy } from "./jwt.strategy";
import { PassportModule } from "@nestjs/passport";
import { JwtStrategy } from "./jwt.strategy";
@Module({
imports: [PassportModule.register({ defaultStrategy: "jwt" })],

View file

@ -12,14 +12,12 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `${config.get<string>(
"JWT_AUTH0_DOMAIN"
)}.well-known/jwks.json`
jwksUri: `${config.get<string>("AUTH0_DOMAIN")}.well-known/jwks.json`
}),
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
audience: config.get<string>("JWT_AUTH0_AUDIENCE"),
issuer: config.get<string>("JWT_AUTH0_DOMAIN"),
audience: config.get<string>("AUTH0_AUDIENCE"),
issuer: config.get<string>("AUTH0_DOMAIN"),
algorithms: ["RS256"]
});
}

View file

@ -1,4 +1,11 @@
import { Controller } from "@nestjs/common";
import { Controller, Get, UseGuards } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
@Controller("connections")
export class ConnectionsController {}
@Controller("api/v1/connections")
export class ConnectionsController {
@Get()
@UseGuards(AuthGuard("jwt"))
get() {
return { msg: "Success!" };
}
}

View file

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FrontendController } from './frontend.controller';
describe('Frontend Controller', () => {
let controller: FrontendController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [FrontendController],
}).compile();
controller = module.get<FrontendController>(FrontendController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View file

@ -0,0 +1,7 @@
import { Controller, Get } from "@nestjs/common";
@Controller("")
export class FrontendController {
@Get()
index() {}
}

View file

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { FrontendController } from './frontend.controller';
@Module({
controllers: [FrontendController]
})
export class FrontendModule {}

View file

@ -1,8 +1,15 @@
import { NestFactory } from "@nestjs/core";
import { NestExpressApplication } from "@nestjs/platform-express";
import { join } from "path";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.useStaticAssets(join(__dirname, "frontend", "public"));
app.setBaseViewsDir(join(__dirname, "frontend", "views"));
app.setViewEngine("mustache");
await app.listen(3000);
}
bootstrap();