mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-28 11:17:16 +00:00
UBERF-5933: Add 404 handling in case of resource direct requests (#4983)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
5b767ce511
commit
d8ef26dc74
@ -9,6 +9,7 @@
|
||||
"sourceMap": true,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"declarationDir": "./types",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"lib": [
|
||||
"es2016",
|
||||
|
@ -79,42 +79,23 @@ async function loadPlugin (id: Plugin): Promise<Resources> {
|
||||
plugin: id
|
||||
})
|
||||
pluginLoader = monitor(status, getLocation(id)()).then(async (plugin) => {
|
||||
return await retryLoading(async () => {
|
||||
try {
|
||||
// In case of ts-node, we have a bit different import structure, so let's check for it.
|
||||
if (typeof plugin.default === 'object') {
|
||||
// eslint-disable-next-line @typescript-eslint/return-await
|
||||
return await (plugin as any).default.default()
|
||||
}
|
||||
return await plugin.default()
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
throw err
|
||||
try {
|
||||
// In case of ts-node, we have a bit different import structure, so let's check for it.
|
||||
if (typeof plugin.default === 'object') {
|
||||
// eslint-disable-next-line @typescript-eslint/return-await
|
||||
return await (plugin as any).default.default()
|
||||
}
|
||||
})
|
||||
return await plugin.default()
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
loading.set(id, pluginLoader)
|
||||
}
|
||||
return await pluginLoader
|
||||
}
|
||||
|
||||
async function retryLoading (op: () => Promise<Resources>): Promise<Resources> {
|
||||
let lastErr: any
|
||||
for (let i = 0; i < 3; i++) {
|
||||
try {
|
||||
return await op()
|
||||
} catch (err: any) {
|
||||
if (/Loading chunk [\d]+ failed/.test(err.message)) {
|
||||
// Do not report on console and try to load again.
|
||||
// After a short delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||
}
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
throw lastErr
|
||||
}
|
||||
|
||||
const cachedResource = new Map<string, any>()
|
||||
|
||||
/**
|
||||
|
@ -172,7 +172,7 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
console.log('Model version', version)
|
||||
|
||||
const requiredVersion = getMetadata(presentation.metadata.RequiredVersion)
|
||||
if (requiredVersion !== undefined && version !== undefined) {
|
||||
if (requiredVersion !== undefined && version !== undefined && requiredVersion !== '') {
|
||||
console.log('checking min model version', requiredVersion)
|
||||
const versionStr = versionToString(version)
|
||||
|
||||
|
@ -24,7 +24,7 @@ import express, { Response } from 'express'
|
||||
import fileUpload, { UploadedFile } from 'express-fileupload'
|
||||
import https from 'https'
|
||||
import morgan from 'morgan'
|
||||
import { join, resolve } from 'path'
|
||||
import { extname, join, resolve } from 'path'
|
||||
import { cwd } from 'process'
|
||||
import sharp from 'sharp'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
@ -556,6 +556,27 @@ export function start (
|
||||
})
|
||||
|
||||
app.get('*', function (request, response) {
|
||||
const url = request.path.split('/').filter((it) => it !== '')
|
||||
if (url.length === 1) {
|
||||
const ext = extname(url[0])
|
||||
const notFoundResource = [
|
||||
'.js',
|
||||
'.js.gz',
|
||||
'.svg',
|
||||
'.webp',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.svg.gz',
|
||||
'.css',
|
||||
'.css.gz',
|
||||
'.png',
|
||||
'.avif'
|
||||
]
|
||||
if (notFoundResource.includes(ext)) {
|
||||
response.sendStatus(404)
|
||||
return
|
||||
}
|
||||
}
|
||||
response.sendFile(join(dist, 'index.html'), {
|
||||
maxAge: cacheControlMaxAge,
|
||||
etag: true,
|
||||
|
Loading…
Reference in New Issue
Block a user