0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core): set server timeout

This commit is contained in:
Gao Sun 2023-03-16 12:10:11 +08:00
parent 8f8c5d4233
commit 1256711bcc
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 13 additions and 3 deletions

View file

@ -1,3 +1,5 @@
import { createServer } from 'http';
import { pickDefault } from '@logto/shared/esm';
import Koa from 'koa';
@ -7,7 +9,9 @@ const initI18n = await pickDefault(import('../i18n/init.js'));
const initApp = await pickDefault(import('./init.js'));
describe('App Init', () => {
const listenMock = jest.spyOn(Koa.prototype, 'listen').mockImplementation(jest.fn());
const listenMock = jest
.spyOn(Koa.prototype, 'listen')
.mockImplementation(jest.fn(() => createServer()));
it('app init properly with 404 not found route', async () => {
const app = new Koa();

View file

@ -17,6 +17,8 @@ const logListening = (type: 'core' | 'admin' = 'core') => {
}
};
const serverTimeout = 120_000;
const getTenant = async (tenantId: string) => {
try {
return await tenantPool.get(tenantId);
@ -76,6 +78,7 @@ export default async function initApp(app: Koa): Promise<void> {
coreServer.listen(urlSet.port, () => {
logListening();
});
coreServer.setTimeout(serverTimeout);
// Create another server if admin localhost enabled
if (!adminUrlSet.isLocalhostDisabled) {
@ -83,20 +86,23 @@ export default async function initApp(app: Koa): Promise<void> {
adminServer.listen(adminUrlSet.port, () => {
logListening('admin');
});
adminServer.setTimeout(serverTimeout);
}
return;
}
// Chrome doesn't allow insecure HTTP/2 servers, stick with HTTP for localhost.
app.listen(urlSet.port, () => {
const coreServer = app.listen(urlSet.port, () => {
logListening();
});
coreServer.setTimeout(serverTimeout);
// Create another server if admin localhost enabled
if (!adminUrlSet.isLocalhostDisabled) {
app.listen(adminUrlSet.port, () => {
const adminServer = app.listen(adminUrlSet.port, () => {
logListening('admin');
});
adminServer.setTimeout(serverTimeout);
}
}