-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payments): add initial NestJS service load on heartbeat
Because: * We want to load/cache the NestJS services on the first request to the app, so that the first request is not slow. * We should use proper NextJS project organization. This commit: * Adds a new route to the app that the loadbalancers utilize, to ensure that the NestJS services are loaded before the first request to the app. * Moves internal implementation that shouldn't be routed to, behind the underscore directory prefix.
- Loading branch information
Showing
11 changed files
with
69 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { NextResponse } from 'next/server'; | ||
|
||
import { app } from '../_nestapp/app'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET(request: Request) { | ||
await app.getApp(); | ||
const resp = new NextResponse('{}'); | ||
resp.headers.set('Content-Type', 'application/json'); | ||
return resp; | ||
} |
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,16 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { NextResponse } from 'next/server'; | ||
|
||
import { app } from '../_nestapp/app'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET(request: Request) { | ||
await app.getApp(); | ||
const resp = new NextResponse('{}'); | ||
resp.headers.set('Content-Type', 'application/json'); | ||
return resp; | ||
} |
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
File renamed without changes.
File renamed without changes.
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,28 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import 'server-only'; | ||
|
||
import { CartService } from '@fxa/payments/cart'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
class AppSingleton { | ||
private app!: Awaited< | ||
ReturnType<typeof NestFactory.createApplicationContext> | ||
>; | ||
|
||
async getApp() { | ||
if (this.app) return this.app; | ||
this.app = await NestFactory.createApplicationContext(AppModule); | ||
return this.app; | ||
} | ||
|
||
async getCartService() { | ||
return (await this.getApp()).get(CartService); | ||
} | ||
} | ||
|
||
export const app = new AppSingleton(); |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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