Skip to content

Commit

Permalink
Merge pull request #171 from zhumeisongsong/feature/use-app-config-in…
Browse files Browse the repository at this point in the history
…-sc-app

feat: ✨ self care app module
  • Loading branch information
zhumeisongsong authored Feb 2, 2025
2 parents 40759ae + f9e85a0 commit 15b66d5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ GATEWAY_PORT=3333
USERS_HOST=localhost
USERS_PORT=15001

TASKS_HOST=localhost
TASKS_PORT=15002
SELF_CARE_TASKS_HOST=localhost
SELF_CARE_TASKS_PORT=15005

AUTH_HOST=localhost
AUTH_PORT=15003
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import axios from 'axios';

describe('GET /api', () => {
it('should return a message', async () => {
const res = await axios.get(`/api`);
const res = await axios.get(`/`);

expect(res.status).toBe(200);
expect(res.data).toEqual({ message: 'Hello API' });
expect(res.data).toEqual({ message: 'Hello Self Care Tasks Service' });
});
});
2 changes: 1 addition & 1 deletion apps/self-care-tasks-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import axios from 'axios';
module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ?? '3000';
const port = process.env.PORT ?? '15005';
axios.defaults.baseURL = `http://${host}:${port}`;
};
4 changes: 2 additions & 2 deletions apps/self-care-tasks/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ describe('AppController', () => {
});

describe('getData', () => {
it('should return "Hello API"', () => {
it('should return "Hello Self Care Tasks Service"', () => {
const appController = app.get<AppController>(AppController);
expect(appController.getData()).toEqual({ message: 'Hello API' });
expect(appController.getData()).toEqual({ message: 'Hello Self Care Tasks Service' });
});
});
});
26 changes: 24 additions & 2 deletions apps/self-care-tasks/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import { selfCareTasksAppConfig } from '@applications/self-care-config';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
import {
ApolloFederationDriver,
ApolloFederationDriverConfig,
} from '@nestjs/apollo';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { GraphQLModule } from '@nestjs/graphql';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [selfCareTasksAppConfig],
}),
GraphQLModule.forRoot<ApolloFederationDriverConfig>({
driver: ApolloFederationDriver,
autoSchemaFile: {
federation: 2,
},
playground: process.env['NODE_ENV'] !== 'production',
sortSchema: true,
plugins: [ApolloServerPluginInlineTrace()],
}),
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
4 changes: 2 additions & 2 deletions apps/self-care-tasks/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('AppService', () => {
});

describe('getData', () => {
it('should return "Hello API"', () => {
expect(service.getData()).toEqual({ message: 'Hello API' });
it('should return "Hello Self Care Tasks Service"', () => {
expect(service.getData()).toEqual({ message: 'Hello Self Care Tasks Service' });
});
});
});
2 changes: 1 addition & 1 deletion apps/self-care-tasks/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getData(): { message: string } {
return { message: 'Hello API' };
return { message: 'Hello Self Care Tasks Service' };
}
}
13 changes: 8 additions & 5 deletions apps/self-care-tasks/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { ConfigService } from '@nestjs/config';

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);

const configService = app.get(ConfigService);
const config = configService.get('selfCareTasksApp');

await app.listen(config.port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,
`🚀 Application is running on: ${config.protocol}://${config.host}:${config.port}`,
);
}

Expand Down

0 comments on commit 15b66d5

Please sign in to comment.