mirror of
https://github.com/vee1e/bulk-questionnaire-upload.git
synced 2026-09-01 09:50:06 +00:00
feat: add Vercel deployment config and runtime API URL loading
- Add vercel.json with Angular build config and SPA rewrites
- Increase Angular bundle budgets to unblock production build
- Fix TS strict null error in runtime-config.ts (return _config ?? {})
- Load API_URL from /assets/config.json at bootstrap via prebuild script
- Wire getRuntimeConfig() into FormService instead of hardcoded localhost
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d247ab12a2
commit
1c0338539e
8 changed files with 52 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -23,3 +23,4 @@ project-plans/
|
|||
.DS_Store
|
||||
.cursorrules
|
||||
tempData.json
|
||||
.vercel
|
||||
|
|
|
|||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
|
|
@ -40,3 +40,4 @@ testem.log
|
|||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
.vercel
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@
|
|||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kB",
|
||||
"maximumError": "1MB"
|
||||
"maximumWarning": "1MB",
|
||||
"maximumError": "2MB"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "4kB",
|
||||
"maximumError": "8kB"
|
||||
"maximumWarning": "16kB",
|
||||
"maximumError": "32kB"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"prebuild": "node -e \"const fs=require('fs');const api=process.env.API_URL||'http://localhost:8000/api';fs.mkdirSync('src/assets', { recursive: true });fs.writeFileSync('src/assets/config.json', JSON.stringify({ API_URL: api }));\"",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"serve:ssr:mform-upload": "node --no-deprecation dist/mform-upload/server/server.mjs",
|
||||
|
|
|
|||
23
frontend/src/app/runtime-config.ts
Normal file
23
frontend/src/app/runtime-config.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export interface RuntimeConfig {
|
||||
API_URL?: string;
|
||||
}
|
||||
|
||||
let _config: RuntimeConfig | null = null;
|
||||
|
||||
export async function loadRuntimeConfig(): Promise<RuntimeConfig> {
|
||||
if (_config) return _config;
|
||||
try {
|
||||
const resp = await fetch('/assets/config.json', { cache: 'no-store' });
|
||||
if (!resp.ok) throw new Error('config.json not found');
|
||||
_config = await resp.json();
|
||||
} catch (e) {
|
||||
// fallback to empty config
|
||||
_config = {};
|
||||
}
|
||||
return _config ?? {};
|
||||
}
|
||||
|
||||
export function getRuntimeConfig(): RuntimeConfig {
|
||||
if (!_config) return {};
|
||||
return _config;
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
|
|||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { FormValidation } from '../models/form.model';
|
||||
import { getRuntimeConfig } from '../runtime-config';
|
||||
|
||||
export interface FormData {
|
||||
id: string;
|
||||
|
|
@ -68,7 +69,7 @@ export interface ParsedSchema {
|
|||
providedIn: 'root'
|
||||
})
|
||||
export class FormService {
|
||||
private readonly apiUrl = 'http://localhost:8000/api';
|
||||
private readonly apiUrl = (getRuntimeConfig().API_URL as string) || 'http://localhost:8000/api';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { loadRuntimeConfig } from './app/runtime-config';
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await loadRuntimeConfig();
|
||||
} catch (e) {
|
||||
console.warn('Failed to load runtime config, proceeding with defaults');
|
||||
}
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig)
|
||||
.catch((err) => console.error(err));
|
||||
})();
|
||||
|
|
|
|||
9
frontend/vercel.json
Normal file
9
frontend/vercel.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"framework": "angular",
|
||||
"buildCommand": "npm run build",
|
||||
"outputDirectory": "dist/mform-upload/browser",
|
||||
"installCommand": "npm install",
|
||||
"rewrites": [
|
||||
{ "source": "/(.*)", "destination": "/index.html" }
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue