From c36b7014a7aed96c6b9c99f268ff7f2c54e8771c Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 12 Nov 2021 13:39:57 +0900 Subject: [PATCH] fix bug --- packages/backend/src/db/postgre.ts | 30 ++++++++++++++++++------ packages/backend/src/server/web/index.ts | 8 +++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/db/postgre.ts b/packages/backend/src/db/postgre.ts index f52c2ab72..efbacf3d1 100644 --- a/packages/backend/src/db/postgre.ts +++ b/packages/backend/src/db/postgre.ts @@ -215,11 +215,27 @@ export function initDb(justBorrow = false, sync = false, forceRecreate = false) } export async function resetDb() { - const conn = await getConnection(); - const tables = await conn.query(`SELECT relname AS "table" - FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) - WHERE nspname NOT IN ('pg_catalog', 'information_schema') - AND C.relkind = 'r' - AND nspname !~ '^pg_toast';`); - await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" CASCADE`))); + const reset = async () => { + const conn = await getConnection(); + const tables = await conn.query(`SELECT relname AS "table" + FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) + WHERE nspname NOT IN ('pg_catalog', 'information_schema') + AND C.relkind = 'r' + AND nspname !~ '^pg_toast';`); + await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" CASCADE`))); + }; + + for (let i = 1; i <= 3; i++) { + try { + await reset(); + } catch (e) { + if (i === 3) { + throw e; + } else { + await new Promise(resolve => setTimeout(resolve, 1000)); + continue; + } + } + break; + } } diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 969b155d4..fc95a36a8 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -23,6 +23,7 @@ const _filename = __filename; const _dirname = dirname(_filename); const staticAssets = `${_dirname}/../../../assets/`; +const clientAssets = `${_dirname}/../../../../client/assets/`; const assets = `${_dirname}/../../../../../built/_client_dist_/`; // Init app @@ -59,6 +60,13 @@ router.get('/static-assets/(.*)', async ctx => { }); }); +router.get('/client-assets/(.*)', async ctx => { + await send(ctx as any, ctx.path.replace('/client-assets/', ''), { + root: clientAssets, + maxage: ms('7 days'), + }); +}); + router.get('/assets/(.*)', async ctx => { await send(ctx as any, ctx.path.replace('/assets/', ''), { root: assets,