refactor(fase1c): routing S3 fixes + auth/swagger/index/env
- routes: GET / teruskan headers ke shouldHandleS3; OPTIONS jawab
204 CORS generik bila bukan S3, handleS3Direct bila S3; komentar
bypass rate-limit S3 dipertahankan (registry abort pada 429)
- auth-controller: readLoginBody via LoginBodySchema; handleMe sederhanakan
(getAuthSession sudah cek bearer); import AuthSession dari dto
- swagger: pindah src/routes -> src/interfaces/http/swagger; tambah path
auth, /api/v1, /{bucket}, /{bucket}/{key}; version dari config.appVersion
- index: unref ketiga setInterval agar tak menahan process
- env: PORT fail-fast via PositiveIntSchema (default 4000 bila tak diset);
log config turun ke debug
- metrics: dokumentasikan uploadThroughput/queueSize/botUtilization
- test baru test/s3-routing.test.ts (GET / S3 vs home, OPTIONS 204 CORS)
This commit is contained in:
@@ -32,6 +32,29 @@ describe('Environment Variables Validation', () => {
|
||||
expect(typeof config.port).toBe('number');
|
||||
});
|
||||
|
||||
it('startup fails fast when PORT is present but invalid', async () => {
|
||||
for (const badPort of ['abc', '-5', '0']) {
|
||||
const proc = Bun.spawn({
|
||||
cmd: ['bun', '-e', "import('./src/env')"],
|
||||
cwd: `${import.meta.dir}/..`,
|
||||
env: {
|
||||
...process.env,
|
||||
BOT_TOKENS: '123456:ABC-DEF',
|
||||
STORAGE_CHANNEL_ID: '-1001234567890',
|
||||
BASE_URL: 'https://example.com',
|
||||
DATABASE_URL: 'postgresql://asephs:***@100.121.180.82:6432/test',
|
||||
PORT: badPort,
|
||||
},
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
});
|
||||
const exitCode = await proc.exited;
|
||||
const stderr = await new Response(proc.stderr).text();
|
||||
expect(exitCode).not.toBe(0);
|
||||
expect(stderr).toContain('PORT must be a positive integer');
|
||||
}
|
||||
});
|
||||
|
||||
it("nodeEnv should be 'test' or 'development'", () => {
|
||||
expect(['test', 'development']).toContain(config.nodeEnv);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user