Skip to content

Commit 056813c

Browse files
committed
Initial commit
1 parent 4fe7a1a commit 056813c

26 files changed

+1542
-424
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../eslint.config.cjs');
2+
3+
module.exports = [...baseConfig];
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
displayName: 'car-rental-backend-e2e',
3+
preset: '../../jest.preset.js',
4+
globalSetup: '<rootDir>/src/support/global-setup.ts',
5+
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
6+
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
7+
testEnvironment: 'node',
8+
transform: {
9+
'^.+\\.[tj]s$': [
10+
'ts-jest',
11+
{
12+
tsconfig: '<rootDir>/tsconfig.spec.json',
13+
},
14+
],
15+
},
16+
moduleFileExtensions: ['ts', 'js', 'html'],
17+
coverageDirectory: '../../coverage/car-rental-backend-e2e',
18+
};
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "car-rental-backend-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"implicitDependencies": ["car-rental-backend"],
6+
"targets": {
7+
"e2e": {
8+
"executor": "@nx/jest:jest",
9+
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
10+
"options": {
11+
"jestConfig": "apps/car-rental-backend-e2e/jest.config.ts",
12+
"passWithNoTests": true
13+
},
14+
"dependsOn": ["car-rental-backend:build"]
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import axios from 'axios';
2+
3+
describe('GET /api', () => {
4+
it('should return a message', async () => {
5+
const res = await axios.get(`/api`);
6+
7+
expect(res.status).toBe(200);
8+
expect(res.data).toEqual({ message: 'Hello API' });
9+
});
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable */
2+
var __TEARDOWN_MESSAGE__: string;
3+
4+
module.exports = async function () {
5+
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
6+
console.log('\nSetting up...\n');
7+
8+
// Hint: Use `globalThis` to pass variables to global teardown.
9+
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable */
2+
3+
module.exports = async function () {
4+
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
5+
// Hint: `globalThis` is shared between setup and teardown.
6+
console.log(globalThis.__TEARDOWN_MESSAGE__);
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
import axios from 'axios';
3+
4+
module.exports = async function () {
5+
// Configure axios for tests to use.
6+
const host = process.env.HOST ?? 'localhost';
7+
const port = process.env.PORT ?? '3000';
8+
axios.defaults.baseURL = `http://${host}:${port}`;
9+
};
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.spec.json"
8+
}
9+
],
10+
"compilerOptions": {
11+
"esModuleInterop": true
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": ["jest.config.ts", "src/**/*.ts"]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../eslint.config.cjs');
2+
3+
module.exports = [...baseConfig];
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
displayName: 'car-rental-backend',
3+
preset: '../../jest.preset.js',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
coverageDirectory: '../../coverage/apps/car-rental-backend',
10+
};

apps/car-rental-backend/project.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "car-rental-backend",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "apps/car-rental-backend/src",
5+
"projectType": "application",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "nx:run-commands",
10+
"options": {
11+
"command": "webpack-cli build",
12+
"args": ["node-env=production"]
13+
},
14+
"configurations": {
15+
"development": {
16+
"args": ["node-env=development"]
17+
}
18+
}
19+
},
20+
"serve": {
21+
"executor": "@nx/js:node",
22+
"defaultConfiguration": "development",
23+
"dependsOn": ["build"],
24+
"options": {
25+
"buildTarget": "car-rental-backend:build",
26+
"runBuildTargetDependencies": false
27+
},
28+
"configurations": {
29+
"development": {
30+
"buildTarget": "car-rental-backend:build:development"
31+
},
32+
"production": {
33+
"buildTarget": "car-rental-backend:build:production"
34+
}
35+
}
36+
},
37+
"test": {
38+
"options": {
39+
"passWithNoTests": true
40+
}
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
5+
describe('AppController', () => {
6+
let app: TestingModule;
7+
8+
beforeAll(async () => {
9+
app = await Test.createTestingModule({
10+
controllers: [AppController],
11+
providers: [AppService],
12+
}).compile();
13+
});
14+
15+
describe('getData', () => {
16+
it('should return "Hello API"', () => {
17+
const appController = app.get<AppController>(AppController);
18+
expect(appController.getData()).toEqual({ message: 'Hello API' });
19+
});
20+
});
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
import { AppService } from './app.service';
3+
4+
@Controller()
5+
export class AppController {
6+
constructor(private readonly appService: AppService) {}
7+
8+
@Get()
9+
getData() {
10+
return this.appService.getData();
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Module } from '@nestjs/common';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
5+
@Module({
6+
imports: [],
7+
controllers: [AppController],
8+
providers: [AppService],
9+
})
10+
export class AppModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Test } from '@nestjs/testing';
2+
import { AppService } from './app.service';
3+
4+
describe('AppService', () => {
5+
let service: AppService;
6+
7+
beforeAll(async () => {
8+
const app = await Test.createTestingModule({
9+
providers: [AppService],
10+
}).compile();
11+
12+
service = app.get<AppService>(AppService);
13+
});
14+
15+
describe('getData', () => {
16+
it('should return "Hello API"', () => {
17+
expect(service.getData()).toEqual({ message: 'Hello API' });
18+
});
19+
});
20+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class AppService {
5+
getData(): { message: string } {
6+
return { message: 'Hello API' };
7+
}
8+
}

apps/car-rental-backend/src/assets/.gitkeep

Whitespace-only changes.

apps/car-rental-backend/src/main.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* This is not a production server yet!
3+
* This is only a minimal backend to get started.
4+
*/
5+
6+
import { Logger } from '@nestjs/common';
7+
import { NestFactory } from '@nestjs/core';
8+
import { AppModule } from './app/app.module';
9+
10+
async function bootstrap() {
11+
const app = await NestFactory.create(AppModule);
12+
const globalPrefix = 'api';
13+
app.setGlobalPrefix(globalPrefix);
14+
const port = process.env.PORT || 3000;
15+
await app.listen(port);
16+
Logger.log(
17+
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
18+
);
19+
}
20+
21+
bootstrap();
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["node"],
7+
"emitDecoratorMetadata": true,
8+
"target": "es2021"
9+
},
10+
"include": ["src/**/*.ts"],
11+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
12+
}

apps/car-rental-backend/tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.app.json"
8+
},
9+
{
10+
"path": "./tsconfig.spec.json"
11+
}
12+
],
13+
"compilerOptions": {
14+
"esModuleInterop": true
15+
}
16+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"moduleResolution": "node10",
7+
"types": ["jest", "node"]
8+
},
9+
"include": [
10+
"jest.config.ts",
11+
"src/**/*.test.ts",
12+
"src/**/*.spec.ts",
13+
"src/**/*.d.ts"
14+
]
15+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
2+
const { join } = require('path');
3+
4+
module.exports = {
5+
output: {
6+
path: join(__dirname, '../../dist/apps/car-rental-backend'),
7+
},
8+
plugins: [
9+
new NxAppWebpackPlugin({
10+
target: 'node',
11+
compiler: 'tsc',
12+
main: './src/main.ts',
13+
tsConfig: './tsconfig.app.json',
14+
assets: ['./src/assets'],
15+
optimization: false,
16+
outputHashing: 'none',
17+
generatePackageJson: true,
18+
}),
19+
],
20+
};

nx.json

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
"options": {
6060
"targetName": "lint"
6161
}
62+
},
63+
{
64+
"plugin": "@nx/webpack/plugin",
65+
"options": {
66+
"buildTargetName": "build",
67+
"serveTargetName": "serve",
68+
"previewTargetName": "preview"
69+
}
6270
}
6371
],
6472
"generators": {

0 commit comments

Comments
 (0)