Added a nestJS based contract api

- Added an example with trucks and basic fetch in useEffect on page load
  - Added simply test to see whether any data is displayed (and shows the interceptor)
Introduced "CypressStrictMode" which wraps React.StrictMode and checks whether Cypress is involved, if so disable StrictMode.
This commit is contained in:
2022-08-15 11:42:19 +02:00
parent c0a0ea66a6
commit 3db77f96b9
31 changed files with 15567 additions and 35 deletions

View File

@@ -0,0 +1,3 @@
export const API_CONSTANTS = {
fake: "fake",
};

View File

@@ -0,0 +1,9 @@
import { Controller, Get } from "@nestjs/common";
@Controller()
export class AppController {
@Get()
getHello(): string {
return "Welcome to the contract api";
}
}

View File

@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { FakeTrucksController } from "./contracts/fake/trucks.controller";
@Module({
imports: [],
controllers: [AppController, FakeTrucksController],
providers: [],
})
export class AppModule {}

View File

@@ -0,0 +1,21 @@
import { Controller, Get } from "@nestjs/common";
import { API_CONSTANTS } from "./../../api.constants";
@Controller(`${API_CONSTANTS.fake}/trucks`)
export class FakeTrucksController {
@Get()
get() {
return [
{
id: "de5ddb70-b2a7-4309-a992-62260a09683a",
licensePlate: "xx-yy-zz",
color: "black",
},
{
id: "087e0b0b-1c13-46e3-8920-762f5738072e",
licensePlate: "xx-yy-zz",
color: "red",
},
];
}
}

12
contracts/api/src/main.ts Normal file
View File

@@ -0,0 +1,12 @@
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// allow app to be called from everywhere
app.enableCors();
// you can disable etags so that you always get 200's instead of 304s :)
// app.getHttpAdapter().getInstance().set("etag", false);
await app.listen(9600);
}
bootstrap();