优化
This commit is contained in:
@@ -6,7 +6,7 @@ const read = path => readFile(new URL(path, import.meta.url), 'utf8')
|
||||
test('H5 image copies only compiled assets and static nginx configuration', async () => {
|
||||
const dockerfile = await read('../deploy/Dockerfile.h5')
|
||||
const copies = dockerfile.split(/\r?\n/).filter(line => line.startsWith('COPY '))
|
||||
assert.deepEqual(copies, ['COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf', 'COPY unpackage/dist/build/web/ /srv/pda-h5/pda-domestic/'])
|
||||
assert.deepEqual(copies, ['COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf', 'COPY unpackage/dist/build/web/ /srv/pda-h5/'])
|
||||
assert.match(dockerfile, /ARG NGINX_BASE_IMAGE=/)
|
||||
assert.match(dockerfile, /FROM \$\{NGINX_BASE_IMAGE\}/)
|
||||
assert.doesNotMatch(dockerfile, /RUN |npm|node_modules|COPY \. /)
|
||||
@@ -15,14 +15,14 @@ test('H5 image copies only compiled assets and static nginx configuration', asyn
|
||||
assert.ok(ignore.includes('!unpackage/dist/build/web/**'))
|
||||
assert.doesNotMatch(ignore, /!\.env|!node_modules|!src/)
|
||||
})
|
||||
test('static server preserves the app prefix and returns genuine missing-resource errors', async () => {
|
||||
test('static server serves the domain root and returns genuine missing-resource errors', async () => {
|
||||
const nginx = await read('../deploy/nginx.conf')
|
||||
assert.match(nginx, /listen 80;/)
|
||||
assert.ok(nginx.includes('location ^~ /pda-domestic/'))
|
||||
assert.ok(nginx.includes('location /'))
|
||||
assert.match(nginx, /root \/srv\/pda-h5;/)
|
||||
assert.match(nginx, /try_files \$uri \$uri\/ =404;/)
|
||||
assert.match(nginx, /Cache-Control "no-store" always/)
|
||||
assert.match(nginx, /location \/ \{ return 404; \}/)
|
||||
assert.doesNotMatch(nginx, /pda-domestic|pda-overseas/)
|
||||
assert.match(nginx, /location = \/healthz/)
|
||||
assert.doesNotMatch(nginx, /proxy_pass|gateway-api|try_files[^;]*index\.html/)
|
||||
})
|
||||
@@ -36,7 +36,7 @@ test('TEST H5 deployment has a required image tag and internal-only dual health
|
||||
assert.match(compose, /external: true/)
|
||||
assert.match(compose, /name: firstleg-test-network/)
|
||||
assert.match(compose, /expose:\s*\n\s*- "80"/)
|
||||
assert.ok(compose.includes('http://127.0.0.1/healthz && wget -qO /dev/null http://127.0.0.1/pda-domestic/'))
|
||||
assert.ok(compose.includes('http://127.0.0.1/healthz && wget -qO /dev/null http://127.0.0.1/'))
|
||||
assert.doesNotMatch(compose, /\bports:|volumes:|API_UPSTREAM|privileged:|pid: host/)
|
||||
})
|
||||
|
||||
@@ -53,8 +53,22 @@ test('only H5 production overrides the toolchain asset base', async () => {
|
||||
process: { env: { UNI_PLATFORM: platform }, cwd: () => '/project' }
|
||||
})
|
||||
assert.equal(factory({ mode }).base,
|
||||
platform === 'h5' && mode === 'production' ? '/pda-domestic/' : undefined,
|
||||
platform === 'h5' && mode === 'production' ? '/' : undefined,
|
||||
`${platform}:${mode}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('H5 proxy uses the shared gateway prefix and preserves API suffixes', async () => {
|
||||
const source = (await read('../vite.config.js')).replace(/^import .*$/gm, '').replace('export default ', '')
|
||||
const factory = runInNewContext(source, {
|
||||
defineConfig: value => value, loadEnv: () => ({ API_PROXY_TARGET: 'https://gateway.example.com' }),
|
||||
uni: () => ({}), process: { env: { UNI_PLATFORM: 'h5' }, cwd: () => '/project' }
|
||||
})
|
||||
const proxy = factory({ mode: 'development' }).server.proxy
|
||||
assert.deepEqual(Object.keys(proxy), ['/gateway-api'])
|
||||
assert.equal(proxy['/gateway-api'].target, 'https://gateway.example.com')
|
||||
for (const suffix of ['/auth/login', '/pda/v1/last-leg/photos/1/download?preview=1']) {
|
||||
assert.equal(proxy['/gateway-api'].rewrite(`/gateway-api${suffix}`), `/api${suffix}`)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user