feat: scaffold center and guild backend NestJS skeletons
This commit is contained in:
10
Fabric.Backend.Center/src/app.module.ts
Normal file
10
Fabric.Backend.Center/src/app.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HealthController } from './common/health.controller';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { NodesModule } from './nodes/nodes.module';
|
||||
|
||||
@Module({
|
||||
imports: [AuthModule, NodesModule],
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class AppModule {}
|
||||
19
Fabric.Backend.Center/src/auth/auth.controller.ts
Normal file
19
Fabric.Backend.Center/src/auth/auth.controller.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
@Post('register')
|
||||
register(@Body() body: Record<string, unknown>) {
|
||||
return { status: 'todo', action: 'register', received: body };
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
login(@Body() body: Record<string, unknown>) {
|
||||
return { status: 'todo', action: 'login', received: body };
|
||||
}
|
||||
|
||||
@Post('refresh')
|
||||
refresh(@Body() body: Record<string, unknown>) {
|
||||
return { status: 'todo', action: 'refresh', received: body };
|
||||
}
|
||||
}
|
||||
7
Fabric.Backend.Center/src/auth/auth.module.ts
Normal file
7
Fabric.Backend.Center/src/auth/auth.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuthController } from './auth.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [AuthController],
|
||||
})
|
||||
export class AuthModule {}
|
||||
9
Fabric.Backend.Center/src/common/health.controller.ts
Normal file
9
Fabric.Backend.Center/src/common/health.controller.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
|
||||
@Controller('healthz')
|
||||
export class HealthController {
|
||||
@Get()
|
||||
get() {
|
||||
return { ok: true, service: 'center' };
|
||||
}
|
||||
}
|
||||
13
Fabric.Backend.Center/src/main.ts
Normal file
13
Fabric.Backend.Center/src/main.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'reflect-metadata';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.setGlobalPrefix('api');
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : 7001;
|
||||
await app.listen(port);
|
||||
console.log(`Fabric.Backend.Center listening on :${port}`);
|
||||
}
|
||||
|
||||
void bootstrap();
|
||||
24
Fabric.Backend.Center/src/nodes/nodes.controller.ts
Normal file
24
Fabric.Backend.Center/src/nodes/nodes.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
|
||||
type NodeRegistration = {
|
||||
nodeId?: string;
|
||||
name?: string;
|
||||
endpoint?: string;
|
||||
handshakeProof?: string;
|
||||
};
|
||||
|
||||
@Controller('nodes')
|
||||
export class NodesController {
|
||||
private readonly nodes: NodeRegistration[] = [];
|
||||
|
||||
@Post('register')
|
||||
register(@Body() body: NodeRegistration) {
|
||||
this.nodes.push(body);
|
||||
return { status: 'accepted', handshake: 'todo-verify-shared-secret', node: body };
|
||||
}
|
||||
|
||||
@Get()
|
||||
list() {
|
||||
return { items: this.nodes };
|
||||
}
|
||||
}
|
||||
7
Fabric.Backend.Center/src/nodes/nodes.module.ts
Normal file
7
Fabric.Backend.Center/src/nodes/nodes.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { NodesController } from './nodes.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [NodesController],
|
||||
})
|
||||
export class NodesModule {}
|
||||
Reference in New Issue
Block a user