- 新增每日数据保留清理任务:按保留期清空原始报文、删除过期 事件/审计记录,批量幂等可重跑;067 迁移补齐清理索引并清理 冗余索引,check-sql-guard 增加防线 - 生产 CORS 改为显式来源白名单(CORS_ALLOWED_ORIGINS),禁用 通配符,非通配响应补充 Vary: Origin - 文件上传任一步失败时回滚已上传对象,清理失败记录 warn 日志 - 新增 HTTP/CORS 与 PostgreSQL 集成测试;若干文件仅 prettier 重排
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { once } from 'node:events'
|
|
import test from 'node:test'
|
|
|
|
import { createApp } from './app.js'
|
|
import { createDefaultRuntimeConfig } from './config/defaults.js'
|
|
import { createStartupState } from './startup/state.js'
|
|
|
|
test('HTTP health route and explicit CORS preflight', async () => {
|
|
const startupState = createStartupState()
|
|
startupState.core.ready = true
|
|
const config = createDefaultRuntimeConfig('/tmp/order-site')
|
|
config.cors.allowedOrigins = ['https://order.example.test']
|
|
const server = createApp({
|
|
startupState,
|
|
isShutdownStarted: () => false,
|
|
config,
|
|
}).listen(0, '127.0.0.1')
|
|
await once(server, 'listening')
|
|
|
|
try {
|
|
const address = server.address()
|
|
assert.ok(address && typeof address === 'object')
|
|
const baseUrl = `http://127.0.0.1:${address.port}`
|
|
const health = await fetch(`${baseUrl}/health/live`)
|
|
assert.equal(health.status, 200)
|
|
assert.equal((await health.json()).data.status, 'alive')
|
|
|
|
const preflight = await fetch(`${baseUrl}/api/v1/health`, {
|
|
method: 'OPTIONS',
|
|
headers: { Origin: 'https://order.example.test' },
|
|
})
|
|
assert.equal(preflight.status, 204)
|
|
assert.equal(preflight.headers.get('access-control-allow-origin'), 'https://order.example.test')
|
|
assert.equal(preflight.headers.get('vary'), 'Origin')
|
|
} finally {
|
|
server.close()
|
|
await once(server, 'close')
|
|
}
|
|
})
|