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:
parent
8f8c5d4233
commit
1256711bcc
2 changed files with 13 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue