-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afba9ca
commit cb3bb1a
Showing
13 changed files
with
389 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fastify from 'fastify'; | ||
import fastifyProxy, { FastifyHttpProxyOptions } from '@fastify/http-proxy'; | ||
|
||
interface MicroserviceData { | ||
uri: string; | ||
prefix: string; | ||
} | ||
|
||
async function bootstrap() { | ||
const fastifyServer = fastify({ logger: { level: 'trace' } }); | ||
|
||
const proxyData: FastifyHttpProxyOptions[] = [ | ||
{ uri: `${process.env.AUTH_API_URL}`, prefix: 'auth' }, | ||
{ uri: `${process.env.TODOS_API_URL}`, prefix: 'todos' }, | ||
].map( | ||
({ uri, prefix }: MicroserviceData): FastifyHttpProxyOptions => ({ | ||
upstream: uri, | ||
prefix: `/:version/${prefix}`, | ||
rewritePrefix: `/:version/${prefix}`, | ||
}), | ||
); | ||
|
||
fastifyServer.get('/', async () => { | ||
return 'Hello Gateway API'; | ||
}); | ||
|
||
for (const proxy of proxyData) { | ||
fastifyServer.register(fastifyProxy, proxy); | ||
} | ||
|
||
fastifyServer.listen( | ||
{ port: +`${process.env.PORT ?? 3000}`, host: '0.0.0.0' }, | ||
(err, address) => { | ||
if (err) throw err; | ||
fastifyServer.log.info(`Server listening on ${address}`); | ||
}, | ||
); | ||
} | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import * as request from 'supertest'; | ||
import { GatewayModule } from './../src/gateway.module'; | ||
|
||
describe('GatewayController (e2e)', () => { | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [GatewayModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
it('/ (GET)', () => { | ||
return request(app.getHttpServer()) | ||
.get('/') | ||
.expect(200) | ||
.expect('Hello World!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"moduleFileExtensions": ["js", "json", "ts"], | ||
"rootDir": ".", | ||
"testEnvironment": "node", | ||
"testRegex": ".e2e-spec.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": false, | ||
"outDir": "../../dist/apps/gateway" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
services: | ||
|
||
gateway: | ||
build: | ||
context: ../ | ||
dockerfile: Dockerfile | ||
target: prod | ||
args: | ||
- SERVICE_NAME=gateway | ||
container_name: gateway | ||
image: gateway | ||
env_file: | ||
- ../.env | ||
environment: | ||
# This overrides the .env file | ||
- HOST=0.0.0.0 | ||
# Mount host directory to docker container to support watch mode | ||
volumes: | ||
- gateway | ||
profiles: | ||
- prod | ||
|
||
|
||
|
||
gateway-dev: | ||
build: | ||
context: ../ | ||
dockerfile: Dockerfile | ||
target: dev | ||
args: | ||
- DOCKER_BUILDKIT=1 | ||
- SERVICE_NAME=gateway | ||
container_name: gateway-dev | ||
image: gateway-dev | ||
env_file: | ||
- ../.env | ||
environment: | ||
# This overrides the .env file | ||
- HOST=0.0.0.0 | ||
# Mount host directory to docker container to support watch mode | ||
volumes: | ||
- ../apps/gateway:/usr/src/app/apps/gateway | ||
- ../libs:/usr/src/app/libs | ||
# This ensures that the NestJS container manages the node_modules folder | ||
# rather than synchronizes it with the host machine | ||
- gateway-node_modules:/usr/src/app/node_modules | ||
profiles: | ||
- dev | ||
command: > | ||
sh -c "cd /usr/src/app | ||
&& npm run db:migrate:latest | ||
&& npm run start:dev -- gateway" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.