9
gateway/.env
Normal file
9
gateway/.env
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
PORT=3001
|
||||
#
|
||||
KEYCLOAK_URL=http://localhost:8080
|
||||
KEYCLOAK_REALM=appweb
|
||||
KEYCLOAK_CLIENT_ID=gateway
|
||||
KEYCLOAK_CLIENT_SECRET=IJQG0mzAdauXlyqh0NsSBpZnI2J8XoI7
|
||||
#
|
||||
SHOP_URL=http://localhost:8080
|
||||
3
gateway/eslint.config.mjs
Normal file
3
gateway/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
import baseConfig from '../eslint.config.mjs';
|
||||
|
||||
export default [...baseConfig];
|
||||
65
gateway/project.json
Normal file
65
gateway/project.json
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "gateway",
|
||||
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "gateway/src",
|
||||
"projectType": "application",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"command": "webpack-cli build",
|
||||
"args": ["--node-env=production"],
|
||||
"cwd": "gateway"
|
||||
},
|
||||
"configurations": {
|
||||
"development": {
|
||||
"args": ["--node-env=development"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"prune-lockfile": {
|
||||
"dependsOn": ["build"],
|
||||
"cache": true,
|
||||
"executor": "@nx/js:prune-lockfile",
|
||||
"outputs": [
|
||||
"{workspaceRoot}/dist/gateway/package.json",
|
||||
"{workspaceRoot}/dist/gateway/pnpm-lock.yaml"
|
||||
],
|
||||
"options": {
|
||||
"buildTarget": "build"
|
||||
}
|
||||
},
|
||||
"copy-workspace-modules": {
|
||||
"dependsOn": ["build"],
|
||||
"cache": true,
|
||||
"outputs": ["{workspaceRoot}/dist/gateway/workspace_modules"],
|
||||
"executor": "@nx/js:copy-workspace-modules",
|
||||
"options": {
|
||||
"buildTarget": "build"
|
||||
}
|
||||
},
|
||||
"prune": {
|
||||
"dependsOn": ["prune-lockfile", "copy-workspace-modules"],
|
||||
"executor": "nx:noop"
|
||||
},
|
||||
"serve": {
|
||||
"continuous": true,
|
||||
"executor": "@nx/js:node",
|
||||
"defaultConfiguration": "development",
|
||||
"dependsOn": ["build"],
|
||||
"options": {
|
||||
"buildTarget": "gateway:build",
|
||||
"runBuildTargetDependencies": false
|
||||
},
|
||||
"configurations": {
|
||||
"development": {
|
||||
"buildTarget": "gateway:build:development"
|
||||
},
|
||||
"production": {
|
||||
"buildTarget": "gateway:build:production"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
gateway/src/app/app.module.ts
Normal file
34
gateway/src/app/app.module.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
||||
import { join } from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { AppService } from './app.service';
|
||||
import { ShopController } from './shopController';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { KeycloakModule } from '@appweb/module';
|
||||
import { TraceMiddleware } from '../common/middleware/trace.middleware';
|
||||
|
||||
const debugPath = join(__dirname, '..', 'environment', '.env');
|
||||
console.log('--- DEBUG ENV ---');
|
||||
console.log('CWD attuale:', process.cwd());
|
||||
console.log('Percorso calcolato:', debugPath);
|
||||
console.log('Il file esiste?', fs.existsSync(debugPath));
|
||||
console.log('-----------------');
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
// 1. Configurazione del ConfigModule con le tue specifiche
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true, // Variabili disponibili ovunque
|
||||
cache: true, // Migliora le performance leggendo dal file solo una volta
|
||||
envFilePath: join(process.cwd(), 'gateway/.env'), // Percorso del file (cercato nella root del workspace Nx)
|
||||
}),
|
||||
KeycloakModule,
|
||||
],
|
||||
providers: [AppService],
|
||||
controllers: [ShopController],
|
||||
})
|
||||
export class AppModule implements NestModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
consumer.apply(TraceMiddleware).forRoutes('*'); // Applica a tutte le rotte
|
||||
}
|
||||
}
|
||||
8
gateway/src/app/app.service.ts
Normal file
8
gateway/src/app/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getData(): { message: string } {
|
||||
return { message: 'Hello API' };
|
||||
}
|
||||
}
|
||||
13
gateway/src/app/shopController.ts
Normal file
13
gateway/src/app/shopController.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Controller, Get, Req } from '@nestjs/common';
|
||||
import { Roles } from 'nest-keycloak-connect';
|
||||
|
||||
@Controller('shop')
|
||||
export class ShopController {
|
||||
@Get('products')
|
||||
@Roles({ roles: ['shop'] })
|
||||
async getProducts(@Req() req) {
|
||||
return {
|
||||
user: req.user,
|
||||
};
|
||||
}
|
||||
}
|
||||
0
gateway/src/assets/.gitkeep
Normal file
0
gateway/src/assets/.gitkeep
Normal file
22
gateway/src/main.ts
Normal file
22
gateway/src/main.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* This is not a production server yet!
|
||||
* This is only a minimal backend to get started.
|
||||
*/
|
||||
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app/app.module';
|
||||
import { join } from 'path';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
const globalPrefix = 'api';
|
||||
app.setGlobalPrefix(globalPrefix);
|
||||
const port = process.env.PORT || 3000;
|
||||
await app.listen(port);
|
||||
Logger.log(
|
||||
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,
|
||||
);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
13
gateway/tsconfig.app.json
Normal file
13
gateway/tsconfig.app.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["node"],
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"target": "es2021",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
13
gateway/tsconfig.json
Normal file
13
gateway/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
25
gateway/webpack.config.js
Normal file
25
gateway/webpack.config.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
output: {
|
||||
path: join(__dirname, '../dist/gateway'),
|
||||
clean: true,
|
||||
...(process.env.NODE_ENV !== 'production' && {
|
||||
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
|
||||
}),
|
||||
},
|
||||
plugins: [
|
||||
new NxAppWebpackPlugin({
|
||||
target: 'node',
|
||||
compiler: 'tsc',
|
||||
main: './src/main.ts',
|
||||
tsConfig: './tsconfig.app.json',
|
||||
assets: ['./src/assets'],
|
||||
optimization: false,
|
||||
outputHashing: 'none',
|
||||
generatePackageJson: true,
|
||||
sourceMap: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user