5
.prettierignore
Normal file
5
.prettierignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Add files here to ignore them from prettier formatting
|
||||||
|
/dist
|
||||||
|
/coverage
|
||||||
|
/.nx/cache
|
||||||
|
/.nx/workspace-data
|
||||||
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
||||||
59
.vscode/launch.json
vendored
Normal file
59
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug gateway with Nx",
|
||||||
|
"runtimeExecutable": "pnpm exec",
|
||||||
|
"runtimeArgs": ["nx", "serve", "gateway"],
|
||||||
|
"env": {
|
||||||
|
"NODE_OPTIONS": "--inspect=9229"
|
||||||
|
},
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"sourceMaps": true,
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/gateway/dist/**/*.(m|c|)js",
|
||||||
|
"!**/node_modules/**"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug shop-service with Nx",
|
||||||
|
"runtimeExecutable": "pnpm exec",
|
||||||
|
"runtimeArgs": ["nx", "serve", "shop-service"],
|
||||||
|
"env": {
|
||||||
|
"NODE_OPTIONS": "--inspect=9230"
|
||||||
|
},
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"sourceMaps": true,
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/shop-service/dist/**/*.(m|c|)js",
|
||||||
|
"!**/node_modules/**"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug user-service with Nx",
|
||||||
|
"runtimeExecutable": "pnpm exec",
|
||||||
|
"runtimeArgs": ["nx", "serve", "user-service"],
|
||||||
|
"env": {
|
||||||
|
"NODE_OPTIONS": "--inspect=9231"
|
||||||
|
},
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"sourceMaps": true,
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/user-service/dist/**/*.(m|c|)js",
|
||||||
|
"!**/node_modules/**"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
42
eslint.config.mjs
Normal file
42
eslint.config.mjs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import nx from '@nx/eslint-plugin';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...nx.configs['flat/base'],
|
||||||
|
...nx.configs['flat/typescript'],
|
||||||
|
...nx.configs['flat/javascript'],
|
||||||
|
{
|
||||||
|
ignores: ['**/dist', '**/out-tsc'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
||||||
|
rules: {
|
||||||
|
'@nx/enforce-module-boundaries': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
enforceBuildableLibDependency: true,
|
||||||
|
allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$'],
|
||||||
|
depConstraints: [
|
||||||
|
{
|
||||||
|
sourceTag: '*',
|
||||||
|
onlyDependOnLibsWithTags: ['*'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
'**/*.ts',
|
||||||
|
'**/*.tsx',
|
||||||
|
'**/*.cts',
|
||||||
|
'**/*.mts',
|
||||||
|
'**/*.js',
|
||||||
|
'**/*.jsx',
|
||||||
|
'**/*.cjs',
|
||||||
|
'**/*.mjs',
|
||||||
|
],
|
||||||
|
// Override or add rules here
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
3
module/README.md
Normal file
3
module/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# module
|
||||||
|
|
||||||
|
This library was generated with [Nx](https://nx.dev).
|
||||||
3
module/eslint.config.mjs
Normal file
3
module/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import baseConfig from '../eslint.config.mjs';
|
||||||
|
|
||||||
|
export default [...baseConfig];
|
||||||
9
module/project.json
Normal file
9
module/project.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "module",
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "module/src",
|
||||||
|
"projectType": "library",
|
||||||
|
"tags": [],
|
||||||
|
"// targets": "to see all targets run: nx show project module --web",
|
||||||
|
"targets": {}
|
||||||
|
}
|
||||||
1
module/src/index.ts
Normal file
1
module/src/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './lib/keycloak.module';
|
||||||
67
module/src/lib/keycloak.module.ts
Normal file
67
module/src/lib/keycloak.module.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AuthGuard, ResourceGuard, RoleGuard } from 'nest-keycloak-connect';
|
||||||
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
import {
|
||||||
|
KeycloakConnectModule,
|
||||||
|
PolicyEnforcementMode,
|
||||||
|
TokenValidation,
|
||||||
|
} from 'nest-keycloak-connect';
|
||||||
|
import { KeycloakConfigKeys } from '@appweb/shared';
|
||||||
|
import { APP_GUARD } from '@nestjs/core';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
KeycloakConnectModule.registerAsync({
|
||||||
|
imports: [ConfigModule],
|
||||||
|
inject: [ConfigService],
|
||||||
|
useFactory: async (config: ConfigService) => {
|
||||||
|
console.debug('URL: ', KeycloakConfigKeys.BASE_URL);
|
||||||
|
console.debug('CLIENT_ID: ', KeycloakConfigKeys.CLIENT_ID);
|
||||||
|
console.debug('REALM: ', KeycloakConfigKeys.REALM);
|
||||||
|
console.debug('CLIENT_SECRET: ', KeycloakConfigKeys.CLIENT_SECRET);
|
||||||
|
// Recuperiamo i valori assicurandoci che non siano undefined
|
||||||
|
const authServerUrl = config.get<string>(KeycloakConfigKeys.BASE_URL);
|
||||||
|
const realm = config.get<string>(KeycloakConfigKeys.REALM);
|
||||||
|
const clientId = config.get<string>(KeycloakConfigKeys.CLIENT_ID);
|
||||||
|
const secret = config.get<string>(KeycloakConfigKeys.CLIENT_SECRET);
|
||||||
|
|
||||||
|
console.debug('authServerUrl: ', authServerUrl);
|
||||||
|
console.debug('realm: ', realm);
|
||||||
|
console.debug('clientId: ', clientId);
|
||||||
|
console.debug('secret: ', secret);
|
||||||
|
|
||||||
|
// Se mancano, NestJS lancerà un errore chiaro all'avvio
|
||||||
|
if (!authServerUrl || !realm || !clientId || !secret) {
|
||||||
|
throw new Error("Mancano variabili d'ambiente critiche per Keycloak");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
authServerUrl,
|
||||||
|
realm,
|
||||||
|
clientId,
|
||||||
|
secret,
|
||||||
|
// Aggiungi queste se necessario per completare il tipo richiesto
|
||||||
|
policyEnforcement: PolicyEnforcementMode.PERMISSIVE,
|
||||||
|
tokenValidation: TokenValidation.ONLINE,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
// Registriamo i Guard qui dentro!
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: AuthGuard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: ResourceGuard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: RoleGuard,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
exports: [KeycloakConnectModule],
|
||||||
|
})
|
||||||
|
export class KeycloakModule {}
|
||||||
20
module/tsconfig.json
Normal file
20
module/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"importHelpers": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.lib.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
17
module/tsconfig.lib.json
Normal file
17
module/tsconfig.lib.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../dist/out-tsc",
|
||||||
|
"declaration": true,
|
||||||
|
"types": ["node"],
|
||||||
|
"target": "es2021",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"strictBindCallApply": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"]
|
||||||
|
}
|
||||||
7
shared/README.md
Normal file
7
shared/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# shared
|
||||||
|
|
||||||
|
This library was generated with [Nx](https://nx.dev).
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Run `nx build shared` to build the library.
|
||||||
19
shared/eslint.config.mjs
Normal file
19
shared/eslint.config.mjs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import baseConfig from '../eslint.config.mjs';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...baseConfig,
|
||||||
|
{
|
||||||
|
files: ['**/*.json'],
|
||||||
|
rules: {
|
||||||
|
'@nx/dependency-checks': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
languageOptions: {
|
||||||
|
parser: await import('jsonc-eslint-parser'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
11
shared/package.json
Normal file
11
shared/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@appweb/shared",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"type": "commonjs",
|
||||||
|
"main": "./src/index.js",
|
||||||
|
"types": "./src/index.d.ts",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
shared/project.json
Normal file
19
shared/project.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "shared",
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "shared/src",
|
||||||
|
"projectType": "library",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "@nx/js:tsc",
|
||||||
|
"outputs": ["{options.outputPath}"],
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/shared",
|
||||||
|
"main": "shared/src/index.ts",
|
||||||
|
"tsConfig": "shared/tsconfig.lib.json",
|
||||||
|
"assets": ["shared/*.md"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
shared/src/index.ts
Normal file
1
shared/src/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './lib/constants';
|
||||||
11
shared/src/lib/constants.ts
Normal file
11
shared/src/lib/constants.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Nomi delle chiavi per le variabili d'ambiente.
|
||||||
|
* Centralizzandole qui, evitiamo di scrivere stringhe a mano nei vari moduli.
|
||||||
|
*/
|
||||||
|
export class KeycloakConfigKeys {
|
||||||
|
static readonly BASE_URL = 'KEYCLOAK_BASE_URL';
|
||||||
|
static readonly URL_AUTH = 'KEYCLOAK_URL_AUTH';
|
||||||
|
static readonly REALM = 'KEYCLOAK_REALM';
|
||||||
|
static readonly CLIENT_ID = 'KEYCLOAK_CLIENT_ID';
|
||||||
|
static readonly CLIENT_SECRET = 'KEYCLOAK_CLIENT_SECRET';
|
||||||
|
}
|
||||||
20
shared/tsconfig.json
Normal file
20
shared/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"importHelpers": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.lib.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
9
shared/tsconfig.lib.json
Normal file
9
shared/tsconfig.lib.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../dist/out-tsc",
|
||||||
|
"declaration": true,
|
||||||
|
"types": ["node"]
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"]
|
||||||
|
}
|
||||||
3
shop-service/eslint.config.mjs
Normal file
3
shop-service/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import baseConfig from '../eslint.config.mjs';
|
||||||
|
|
||||||
|
export default [...baseConfig];
|
||||||
65
shop-service/project.json
Normal file
65
shop-service/project.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"name": "shop-service",
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "shop-service/src",
|
||||||
|
"projectType": "application",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "nx:run-commands",
|
||||||
|
"options": {
|
||||||
|
"command": "webpack-cli build",
|
||||||
|
"args": ["--node-env=production"],
|
||||||
|
"cwd": "shop-service"
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"args": ["--node-env=development"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"prune-lockfile": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"cache": true,
|
||||||
|
"executor": "@nx/js:prune-lockfile",
|
||||||
|
"outputs": [
|
||||||
|
"{workspaceRoot}/dist/shop-service/package.json",
|
||||||
|
"{workspaceRoot}/dist/shop-service/pnpm-lock.yaml"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"buildTarget": "build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"copy-workspace-modules": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"cache": true,
|
||||||
|
"outputs": ["{workspaceRoot}/dist/shop-service/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": "shop-service:build",
|
||||||
|
"runBuildTargetDependencies": false
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"buildTarget": "shop-service:build:development"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"buildTarget": "shop-service:build:production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
shop-service/src/app/app.controller.ts
Normal file
12
shop-service/src/app/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getData() {
|
||||||
|
return this.appService.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
shop-service/src/app/app.module.ts
Normal file
10
shop-service/src/app/app.module.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
8
shop-service/src/app/app.service.ts
Normal file
8
shop-service/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' };
|
||||||
|
}
|
||||||
|
}
|
||||||
0
shop-service/src/assets/.gitkeep
Normal file
0
shop-service/src/assets/.gitkeep
Normal file
21
shop-service/src/main.ts
Normal file
21
shop-service/src/main.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* 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';
|
||||||
|
|
||||||
|
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
shop-service/tsconfig.app.json
Normal file
13
shop-service/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
shop-service/tsconfig.json
Normal file
13
shop-service/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.app.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
||||||
25
shop-service/webpack.config.js
Normal file
25
shop-service/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/shop-service'),
|
||||||
|
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
23
tsconfig.base.json
Normal file
23
tsconfig.base.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": ".",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"importHelpers": true,
|
||||||
|
"target": "es2015",
|
||||||
|
"module": "esnext",
|
||||||
|
"lib": ["es2020", "dom"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"skipDefaultLibCheck": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@appweb/shared": ["shared/src/index.ts"],
|
||||||
|
"@appweb/module": ["module/src/index.ts"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exclude": ["node_modules", "tmp"]
|
||||||
|
}
|
||||||
3
user-service/eslint.config.mjs
Normal file
3
user-service/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import baseConfig from '../eslint.config.mjs';
|
||||||
|
|
||||||
|
export default [...baseConfig];
|
||||||
65
user-service/project.json
Normal file
65
user-service/project.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"name": "user-service",
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "user-service/src",
|
||||||
|
"projectType": "application",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "nx:run-commands",
|
||||||
|
"options": {
|
||||||
|
"command": "webpack-cli build",
|
||||||
|
"args": ["--node-env=production"],
|
||||||
|
"cwd": "user-service"
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"args": ["--node-env=development"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"prune-lockfile": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"cache": true,
|
||||||
|
"executor": "@nx/js:prune-lockfile",
|
||||||
|
"outputs": [
|
||||||
|
"{workspaceRoot}/dist/user-service/package.json",
|
||||||
|
"{workspaceRoot}/dist/user-service/pnpm-lock.yaml"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"buildTarget": "build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"copy-workspace-modules": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"cache": true,
|
||||||
|
"outputs": ["{workspaceRoot}/dist/user-service/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": "user-service:build",
|
||||||
|
"runBuildTargetDependencies": false
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"buildTarget": "user-service:build:development"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"buildTarget": "user-service:build:production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
user-service/src/app/app.controller.ts
Normal file
12
user-service/src/app/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getData() {
|
||||||
|
return this.appService.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
21
user-service/src/app/app.module.ts
Normal file
21
user-service/src/app/app.module.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { KeycloakModule } from '@appweb/module';
|
||||||
|
|
||||||
|
@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(), 'user-service/.env'), // Percorso del file (cercato nella root del workspace Nx)
|
||||||
|
}),
|
||||||
|
KeycloakModule,
|
||||||
|
],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
8
user-service/src/app/app.service.ts
Normal file
8
user-service/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' };
|
||||||
|
}
|
||||||
|
}
|
||||||
0
user-service/src/assets/.gitkeep
Normal file
0
user-service/src/assets/.gitkeep
Normal file
21
user-service/src/main.ts
Normal file
21
user-service/src/main.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* 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';
|
||||||
|
|
||||||
|
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
user-service/tsconfig.app.json
Normal file
13
user-service/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
user-service/tsconfig.json
Normal file
13
user-service/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.app.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
||||||
25
user-service/webpack.config.js
Normal file
25
user-service/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/user-service'),
|
||||||
|
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