mirror of
https://github.com/Mastermindzh/react-starter-kit.git
synced 2025-08-05 17:09:09 +02:00
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:
3
contracts/api/src/api.constants.ts
Normal file
3
contracts/api/src/api.constants.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const API_CONSTANTS = {
|
||||
fake: "fake",
|
||||
};
|
9
contracts/api/src/app.controller.ts
Normal file
9
contracts/api/src/app.controller.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return "Welcome to the contract api";
|
||||
}
|
||||
}
|
10
contracts/api/src/app.module.ts
Normal file
10
contracts/api/src/app.module.ts
Normal 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 {}
|
21
contracts/api/src/contracts/fake/trucks.controller.ts
Normal file
21
contracts/api/src/contracts/fake/trucks.controller.ts
Normal 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
12
contracts/api/src/main.ts
Normal 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();
|
Reference in New Issue
Block a user