Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add auth app #113

Merged
merged 2 commits into from
Dec 10, 2024
Merged

feat: ✨ add auth app #113

merged 2 commits into from
Dec 10, 2024

Conversation

zhumeisongsong
Copy link
Owner

@zhumeisongsong zhumeisongsong commented Dec 10, 2024

Related #97 #71

image

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new environment variables for authentication service configuration.
    • Added new Jest and ESLint configuration files for auth and auth-e2e applications.
    • Implemented a new authentication controller and service with a basic endpoint returning a message.
    • Enhanced Apollo Gateway configuration to integrate the authentication service.
  • Bug Fixes

    • Updated Jest configuration to ensure proper test execution and coverage reporting.
  • Documentation

    • New project configuration files for auth and auth-e2e applications added.
  • Chores

    • Updated nx.json to exclude specific end-to-end test files from Jest processing.
    • Modified Axios configuration in test setups for various applications to use new environment variables.

Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

This pull request introduces several new configuration files and updates to support an authentication service within an application. Key changes include the addition of environment variables in the .env.sample file, new Jest and ESLint configurations for the auth-e2e application, and a new project configuration file. Additionally, several new files related to global setup and teardown for tests have been created, along with the introduction of a basic authentication controller and service. The changes enhance the overall structure and functionality of the authentication service.

Changes

File Path Change Summary
.env.sample Added environment variables: AUTH_HOST=localhost, AUTH_PORT=15003.
apps/auth-e2e/eslint.config.js Introduced a new ESLint configuration file extending base settings.
apps/auth-e2e/jest.config.ts Created a Jest configuration file for end-to-end testing with setup and teardown scripts.
apps/auth-e2e/project.json Added a project configuration for auth-e2e, defining targets and dependencies.
apps/auth-e2e/src/auth/auth.spec.ts Introduced a new test suite for the GET / endpoint, verifying successful response.
apps/auth-e2e/src/support/global-setup.ts Created a global setup file for initializing services before tests.
apps/auth-e2e/src/support/global-teardown.ts Created a global teardown file for cleanup after tests.
apps/auth-e2e/src/support/test-setup.ts Introduced a test setup file for configuring Axios with environment variables.
apps/auth-e2e/tsconfig.json Added a TypeScript configuration file extending base settings.
apps/auth-e2e/tsconfig.spec.json Created a TypeScript configuration for testing, specifying output and module system.
apps/auth/eslint.config.js Introduced a new ESLint configuration file for the auth application.
apps/auth/jest.config.ts Created a Jest configuration file for the auth application.
apps/auth/project.json Added a project configuration for the auth application with targets and build settings.
apps/auth/src/app/app.controller.spec.ts Introduced a test suite for the AppController, testing the getData method.
apps/auth/src/app/app.controller.ts Created the AppController class with a getData method.
apps/auth/src/app/app.module.ts Added the main application module for the authentication service, integrating necessary modules.
apps/auth/src/app/app.service.spec.ts Introduced a test suite for the AppService, testing the getData method.
apps/auth/src/app/app.service.ts Created the AppService class with a getData method returning a message.
apps/auth/src/main.ts Introduced the main entry point for the application, initializing the NestJS server.
apps/auth/tsconfig.app.json Added a TypeScript configuration file for the auth application.
apps/auth/tsconfig.json Created a TypeScript configuration file extending base settings.
apps/auth/tsconfig.spec.json Added a TypeScript configuration for testing in the auth application.
apps/auth/webpack.config.js Introduced a Webpack configuration file for the auth application.
apps/gateway/src/app/app.module.ts Updated the AppModule to include the new authAppConfig for the authentication service.
libs/shared/config/src/lib/applications.config.ts Added configuration for the authentication service, including authAppConfig and DEFAULT_PORT.
nx.json Updated the exclude array in the nx.json configuration to include paths for auth-e2e tests.

Possibly related PRs

🐰 In the garden where we play,
New configs bloom bright today.
Auth and tests, all in a row,
Hop along, let the features grow!
With every line, we build and cheer,
A joyful code, we hold so dear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (11)
apps/auth/src/app/app.service.ts (1)

1-8: LGTM, but this appears to be just a placeholder implementation.

While the implementation is correct, as an authentication service, it should provide core authentication functionality.

Consider adding essential auth methods such as:

  • register(credentials: RegisterDto): Promise<User>
  • login(credentials: LoginDto): Promise<AuthToken>
  • validateToken(token: string): Promise<User>
  • refreshToken(token: string): Promise<AuthToken>
apps/auth-e2e/src/support/test-setup.ts (1)

1-10: Consider adding type safety and request timeout.

The setup could benefit from additional configuration for robust e2e testing.

Consider these improvements:

import axios, { AxiosError } from 'axios';

interface TestConfig {
  host: string;
  port: number;
  timeout: number;
}

module.exports = async function () {
  const config: TestConfig = {
    host: process.env.AUTH_HOST ?? 'localhost',
    port: Number(process.env.AUTH_PORT ?? '15003'),
    timeout: Number(process.env.AUTH_TIMEOUT ?? '5000'),
  };

  // Validate config
  if (isNaN(config.port)) {
    throw new Error('AUTH_PORT must be a valid number');
  }

  axios.defaults.baseURL = `http://${config.host}:${config.port}`;
  axios.defaults.timeout = config.timeout;
  
  // Add response interceptor for better error handling
  axios.interceptors.response.use(
    response => response,
    (error: AxiosError) => {
      console.error(`Test request failed: ${error.message}`);
      return Promise.reject(error);
    }
  );
};
apps/auth/src/app/app.controller.ts (1)

1-3: Consider adding authentication guards

As this is an auth module, consider adding appropriate authentication/authorization guards to protect the endpoints.

Example:

import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';

@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
apps/auth-e2e/src/support/global-setup.ts (1)

1-3: Improve type declaration

Consider using a more specific type declaration for the teardown message.

-var __TEARDOWN_MESSAGE__: string;
+declare global {
+  var __TEARDOWN_MESSAGE__: string;
+}
apps/auth/webpack.config.js (1)

9-18: Consider enabling optimization for production builds

While disabling optimization is fine for development, consider adding a conditional configuration for production builds:

 new NxAppWebpackPlugin({
   target: 'node',
   compiler: 'tsc',
   main: './src/main.ts',
   tsConfig: './tsconfig.app.json',
   assets: ['./src/assets'],
-  optimization: false,
+  optimization: process.env.NODE_ENV === 'production',
   outputHashing: 'none',
   generatePackageJson: true,
 }),
apps/auth-e2e/jest.config.ts (1)

17-17: Consider adding coverage thresholds

Add coverage thresholds to ensure maintaining test coverage standards:

 coverageDirectory: '../../coverage/auth-e2e',
+coverageThreshold: {
+  global: {
+    branches: 80,
+    functions: 80,
+    lines: 80,
+    statements: 80
+  }
+},
apps/auth/src/app/app.controller.spec.ts (1)

1-5: Add e2e test configuration

Since this is an auth service, consider adding separate e2e tests for full authentication flows.

Create a new e2e test file with scenarios like:

  • User registration flow
  • Login flow
  • Token refresh flow
  • Password reset flow
  • Session management
libs/shared/config/src/lib/applications.config.ts (1)

57-65: Consider standardizing environment variable naming

The implementation looks good and follows the established pattern. However, for better consistency with other services, consider using AUTH_APP_HOST and AUTH_APP_PORT instead of AUTH_HOST and AUTH_PORT to match the naming pattern used in the config key authApp.

-    host: process.env['AUTH_HOST'] ?? DEFAULT_HOST,
-    port: process.env['AUTH_PORT'] ? Number(process.env['AUTH_PORT']) : DEFAULT_PORT.auth,
+    host: process.env['AUTH_APP_HOST'] ?? DEFAULT_HOST,
+    port: process.env['AUTH_APP_PORT'] ? Number(process.env['AUTH_APP_PORT']) : DEFAULT_PORT.auth,
apps/auth/src/app/app.module.ts (2)

1-18: Consider organizing imports by category

The imports look good but could be better organized for maintainability.

+ // Apollo
 import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
 import {
   ApolloFederationDriver,
   ApolloFederationDriverConfig,
 } from '@nestjs/apollo';
+ 
+ // NestJS
 import { Module } from '@nestjs/common';
 import { ConfigModule } from '@nestjs/config';
 import { GraphQLModule } from '@nestjs/graphql';
+ 
+ // Configuration
 import {
   databaseConfig,
   authAppConfig,
   awsConfig,
   authConfig,
 } from '@shared/config';
+ 
+ // Modules
 import { AuthModule } from '@auth/interface-adapters';
 
+ // Local
 import { AppController } from './app.controller';
 import { AppService } from './app.service';

26-39: Consider additional GraphQL security measures

The GraphQL configuration looks good, but consider adding these security enhancements:

  • Query complexity limits
  • Rate limiting
  • Request timeout
 GraphQLModule.forRoot<ApolloFederationDriverConfig>({
   driver: ApolloFederationDriver,
   autoSchemaFile: {
     federation: 2,
   },
   playground: process.env['NODE_ENV'] !== 'production',
   sortSchema: true,
   plugins: [ApolloServerPluginInlineTrace()],
+  // Prevent complex queries from overloading the server
+  complexity: {
+    max: 20,
+  },
+  // Set timeout for long-running queries
+  context: ({ req }) => ({
+    req,
+    timeout: 10000,
+  }),
 }),
apps/gateway/src/app/app.module.ts (1)

39-42: Consider authentication flow in federated setup.

Since this is adding an auth subgraph to the federation:

  1. Ensure proper JWT validation across services
  2. Consider implementing authentication directives at the gateway level
  3. Plan for secure service-to-service communication
  4. Consider rate limiting for auth-related operations

Resources:

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 649f26f and 0e660cb.

📒 Files selected for processing (26)
  • .env.sample (1 hunks)
  • apps/auth-e2e/eslint.config.js (1 hunks)
  • apps/auth-e2e/jest.config.ts (1 hunks)
  • apps/auth-e2e/project.json (1 hunks)
  • apps/auth-e2e/src/auth/auth.spec.ts (1 hunks)
  • apps/auth-e2e/src/support/global-setup.ts (1 hunks)
  • apps/auth-e2e/src/support/global-teardown.ts (1 hunks)
  • apps/auth-e2e/src/support/test-setup.ts (1 hunks)
  • apps/auth-e2e/tsconfig.json (1 hunks)
  • apps/auth-e2e/tsconfig.spec.json (1 hunks)
  • apps/auth/eslint.config.js (1 hunks)
  • apps/auth/jest.config.ts (1 hunks)
  • apps/auth/project.json (1 hunks)
  • apps/auth/src/app/app.controller.spec.ts (1 hunks)
  • apps/auth/src/app/app.controller.ts (1 hunks)
  • apps/auth/src/app/app.module.ts (1 hunks)
  • apps/auth/src/app/app.service.spec.ts (1 hunks)
  • apps/auth/src/app/app.service.ts (1 hunks)
  • apps/auth/src/main.ts (1 hunks)
  • apps/auth/tsconfig.app.json (1 hunks)
  • apps/auth/tsconfig.json (1 hunks)
  • apps/auth/tsconfig.spec.json (1 hunks)
  • apps/auth/webpack.config.js (1 hunks)
  • apps/gateway/src/app/app.module.ts (4 hunks)
  • libs/shared/config/src/lib/applications.config.ts (2 hunks)
  • nx.json (1 hunks)
✅ Files skipped from review due to trivial changes (10)
  • apps/auth/eslint.config.js
  • apps/auth-e2e/eslint.config.js
  • apps/auth-e2e/tsconfig.json
  • apps/auth-e2e/src/support/global-teardown.ts
  • apps/auth/tsconfig.json
  • apps/auth/tsconfig.spec.json
  • apps/auth/tsconfig.app.json
  • apps/auth/project.json
  • apps/auth/jest.config.ts
  • apps/auth-e2e/tsconfig.spec.json
🔇 Additional comments (11)
apps/auth/webpack.config.js (1)

5-7: LGTM: Output path follows Nx workspace convention

The output path is correctly configured to dist/apps/auth relative to the workspace root.

apps/auth-e2e/jest.config.ts (1)

4-6: Verify existence of global setup and teardown files

Ensure that the referenced setup and teardown files exist:

✅ Verification successful

All required Jest setup files are present

The verification confirms that all referenced setup files exist in the correct locations:

  • apps/auth-e2e/src/support/global-setup.ts
  • apps/auth-e2e/src/support/global-teardown.ts
  • apps/auth-e2e/src/support/test-setup.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the global setup/teardown files exist
files=(
  "apps/auth-e2e/src/support/global-setup.ts"
  "apps/auth-e2e/src/support/global-teardown.ts"
  "apps/auth-e2e/src/support/test-setup.ts"
)

for file in "${files[@]}"; do
  if [ ! -f "$file" ]; then
    echo "Missing file: $file"
  fi
done

Length of output: 404


Script:

#!/bin/bash
# Let's use fd to search for these files as it's more reliable
fd -t f "global-setup.ts|global-teardown.ts|test-setup.ts" apps/auth-e2e/src/support

Length of output: 213

apps/auth-e2e/project.json (3)

4-5: LGTM: Correct project type and dependencies

The project is correctly configured as an application with an implicit dependency on the auth project.


14-14: LGTM: Proper build dependency

The e2e tests correctly depend on the auth project being built first.


11-13: 🛠️ Refactor suggestion

Reconsider allowing tests to pass with no tests

The passWithNoTests option is set to true, which might hide the fact that e2e tests are missing:

Consider setting this to false once you have your initial test suite in place to ensure e2e test coverage is maintained.

✅ Verification successful

passWithNoTests setting can be safely removed

The project already has active e2e tests in place:

  • apps/auth-e2e/src/auth/auth.spec.ts contains a functional test suite for the auth endpoint
  • apps/auth-e2e/src/support/test-setup.ts includes test support code

Since there are actual tests present and running, the passWithNoTests setting is unnecessary and can be safely set to false to ensure e2e test coverage is maintained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any test files in the e2e project
test_files=$(find apps/auth-e2e/src -name "*.spec.ts" -o -name "*.test.ts")
if [ -z "$test_files" ]; then
  echo "Warning: No test files found in apps/auth-e2e/src"
fi

Length of output: 162


Script:

#!/bin/bash
# Let's check the content of the test file to see if it contains actual tests
cat apps/auth-e2e/src/auth/auth.spec.ts

# Also check if there are any other test-related files
find apps/auth-e2e/src -type f -exec grep -l "test\|describe\|it(" {} \;

Length of output: 442

apps/auth/src/main.ts (1)

15-16: Verify configuration handling

Add type safety and validation for the config object.

libs/shared/config/src/lib/applications.config.ts (1)

16-19: LGTM! Port assignment follows established pattern

The auth service port (15003) is correctly assigned following the sequential pattern of existing microservices.

nx.json (1)

40-41: LGTM! Verify auth-e2e directory setup

The exclusion pattern follows the established configuration for other e2e test suites.

✅ Verification successful

Directory structure and configuration files verified

The auth-e2e directory exists at the expected location with required configuration files (jest.config.ts and project.json) in place, confirming proper e2e test setup.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence of auth-e2e directory and its configuration
fd -t d "auth-e2e$" apps/
fd -t f "jest.config.ts|project.json" apps/auth-e2e/

Length of output: 153

apps/gateway/src/app/app.module.ts (3)

2-2: LGTM! Import statement follows established patterns.

The addition of authAppConfig maintains consistency with existing imports and follows the project's naming conventions.


15-15: LGTM! Configuration module setup is correct.

The authAppConfig is properly integrated into the global configuration setup, maintaining consistency with the existing pattern.


24-24: Consider adding validation and error handling for the auth configuration.

While the implementation follows the established pattern, consider these improvements for robustness:

  1. Add validation to ensure all required auth config properties exist
  2. Implement URL sanitization for the constructed endpoint
  3. Add error handling for configuration loading

Let's verify the auth config structure:

Consider adding validation like this:

// In the useFactory
const authAppConfig = configService.get('authApp');
if (!authAppConfig?.host || !authAppConfig?.port || !authAppConfig?.protocol) {
  throw new Error('Invalid auth app configuration');
}

Also applies to: 39-42

apps/auth-e2e/src/auth/auth.spec.ts Show resolved Hide resolved
apps/auth-e2e/src/support/test-setup.ts Outdated Show resolved Hide resolved
apps/auth/src/app/app.controller.ts Show resolved Hide resolved
.env.sample Show resolved Hide resolved
apps/auth-e2e/src/support/global-setup.ts Show resolved Hide resolved
apps/auth/src/app/app.service.spec.ts Show resolved Hide resolved
apps/auth/src/main.ts Show resolved Hide resolved
apps/auth/src/app/app.controller.spec.ts Show resolved Hide resolved
apps/auth/src/app/app.module.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
apps/gateway-e2e/src/support/test-setup.ts (1)

7-8: LGTM! Consider documenting environment variables.

The renaming of environment variables to include the GATEWAY_ prefix is a good change that prevents naming conflicts as the application grows to include multiple services.

Consider adding a comment block documenting these environment variables and their purpose:

/* eslint-disable */

import axios from 'axios';

+/**
+ * Environment variables:
+ * - GATEWAY_HOST: Host address for the gateway service (default: 'localhost')
+ * - GATEWAY_PORT: Port number for the gateway service (default: '3333')
+ */
module.exports = async function () {
apps/users-e2e/src/support/test-setup.ts (2)

7-9: Consider adding validation for connection parameters.

While the default values are sensible, consider adding validation to ensure:

  • Port number is within valid range (0-65535)
  • Host format is valid
  • Service is actually reachable before tests begin
 const host = process.env.USERS_HOST ?? 'localhost';
 const port = process.env.USERS_PORT ?? '15001';
+const portNum = parseInt(port, 10);
+if (isNaN(portNum) || portNum < 0 || portNum > 65535) {
+  throw new Error(`Invalid port number: ${port}`);
+}
+
 axios.defaults.baseURL = `http://${host}:${port}`;
+
+// Verify service is reachable
+try {
+  await axios.get('/health');
+} catch (error) {
+  throw new Error(`Users service not reachable at ${axios.defaults.baseURL}`);
+}

7-9: Consider implementing service discovery for test environments.

As the number of services grows (users, auth, etc.), managing individual host/port configurations becomes more complex. Consider implementing a service discovery mechanism or a central test configuration service.

This could involve:

  1. Using a service registry (e.g., Consul, Eureka)
  2. Implementing a test-specific service discovery mechanism
  3. Using Docker Compose for test environments with service name resolution
apps/tasks-e2e/src/support/test-setup.ts (2)

4-9: Consider TypeScript improvements

While the code is functional, we can improve type safety and maintainability.

Consider this enhanced version:

/* eslint-disable */
import axios from 'axios';

-module.exports = async function () {
+interface ServiceConfig {
+  host: string;
+  port: string;
+}
+
+export const getServiceConfig = (): ServiceConfig => ({
+  host: process.env.TASKS_HOST ?? 'localhost',
+  port: process.env.TASKS_PORT ?? '15002',
+});
+
+export default async function setupAxios(): Promise<void> {
-  const host = process.env.TASKS_HOST ?? 'localhost';
-  const port = process.env.TASKS_PORT ?? '15002';
+  const { host, port } = getServiceConfig();
   axios.defaults.baseURL = `http://${host}:${port}`;
-};
+}

This refactor:

  1. Uses proper TypeScript exports
  2. Separates config logic for better testing
  3. Adds type safety with interfaces

Line range hint 1-1: Remove eslint-disable comment

Instead of disabling ESLint completely, consider addressing specific rules if needed.

-/* eslint-disable */
+// TODO: Address specific ESLint rules if needed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e660cb and 12870f1.

📒 Files selected for processing (4)
  • apps/auth-e2e/src/support/test-setup.ts (1 hunks)
  • apps/gateway-e2e/src/support/test-setup.ts (1 hunks)
  • apps/tasks-e2e/src/support/test-setup.ts (1 hunks)
  • apps/users-e2e/src/support/test-setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/auth-e2e/src/support/test-setup.ts
🔇 Additional comments (3)
apps/gateway-e2e/src/support/test-setup.ts (1)

7-9: Verify port number consistency across services.

Since this PR introduces a new auth service alongside the gateway, let's ensure port numbers are consistently configured across services.

✅ Verification successful

Port configurations are consistent across services

The port configurations are well-organized and consistent across the codebase:

  • Gateway service uses port 3333
  • Users service uses port 15001
  • Tasks service uses port 15002
  • Auth service uses port 15003

Each service has a dedicated port range, with microservices using 15xxx range and the gateway using 3333, preventing any conflicts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check port configurations across different services to ensure consistency
# Expected: Find all port configurations to verify they don't conflict

# Search for port configurations in environment files
echo "Checking environment files for port configurations:"
rg -n "PORT=" --type-add 'env:*.{env,env.*}'  --type env

# Search for hardcoded port numbers in setup files
echo -e "\nChecking setup files for port configurations:"
fd -e ts -e js test-setup | xargs rg -n "port.*=.*\d{4}"

Length of output: 868

apps/users-e2e/src/support/test-setup.ts (1)

7-8: LGTM! Clear and consistent environment variable naming.

The change to use service-specific environment variables (USERS_HOST, USERS_PORT) improves clarity and prevents conflicts in a multi-service architecture.

apps/tasks-e2e/src/support/test-setup.ts (1)

6-7: Verify port allocation scheme across services

The default port 15002 for the tasks service suggests a planned port allocation scheme (auth:15003, tasks:15002). Let's verify this is consistent across services.

Consider documenting the port allocation scheme in a central location (e.g., README.md) to make it easier for developers to understand the service port assignments.

✅ Verification successful

Port allocation scheme is consistent across services

The verification confirms a clear and consistent port allocation scheme across the microservices:

  • Users service: 15001
  • Tasks service: 15002
  • Auth service: 15003

This follows a logical sequential numbering pattern, indicating good architectural planning.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for port allocations across services to ensure consistency
# Expected: Find all port configurations to verify they follow the planned scheme

# Search for port configurations in environment files
echo "Checking environment files for port configurations:"
rg -n "PORT.*=.*150\d{2}" --type env

# Search for hardcoded ports in source files
echo "Checking source files for port configurations:"
rg -n "port.*=.*['\"](150\d{2})['\"]" --type ts

Length of output: 613

@zhumeisongsong zhumeisongsong merged commit f7d68f1 into main Dec 10, 2024
5 checks passed
@zhumeisongsong zhumeisongsong deleted the feature/add-auth-app branch December 10, 2024 09:14
Copy link

🎉 This PR is included in version 1.15.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant