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
|
.DS_Store
|
||||||
.cursorrules
|
.cursorrules
|
||||||
tempData.json
|
tempData.json
|
||||||
|
.vercel
|
||||||
|
|
|
||||||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
|
|
@ -40,3 +40,4 @@ testem.log
|
||||||
# System files
|
# System files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
.vercel
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,13 @@
|
||||||
"budgets": [
|
"budgets": [
|
||||||
{
|
{
|
||||||
"type": "initial",
|
"type": "initial",
|
||||||
"maximumWarning": "500kB",
|
"maximumWarning": "1MB",
|
||||||
"maximumError": "1MB"
|
"maximumError": "2MB"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "anyComponentStyle",
|
"type": "anyComponentStyle",
|
||||||
"maximumWarning": "4kB",
|
"maximumWarning": "16kB",
|
||||||
"maximumError": "8kB"
|
"maximumError": "32kB"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"outputHashing": "all"
|
"outputHashing": "all"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"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",
|
"build": "ng build",
|
||||||
"watch": "ng build --watch --configuration development",
|
"watch": "ng build --watch --configuration development",
|
||||||
"serve:ssr:mform-upload": "node --no-deprecation dist/mform-upload/server/server.mjs",
|
"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 { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { FormValidation } from '../models/form.model';
|
import { FormValidation } from '../models/form.model';
|
||||||
|
import { getRuntimeConfig } from '../runtime-config';
|
||||||
|
|
||||||
export interface FormData {
|
export interface FormData {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
@ -68,7 +69,7 @@ export interface ParsedSchema {
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class FormService {
|
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) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
import { bootstrapApplication } from '@angular/platform-browser';
|
import { bootstrapApplication } from '@angular/platform-browser';
|
||||||
import { appConfig } from './app/app.config';
|
import { appConfig } from './app/app.config';
|
||||||
import { AppComponent } from './app/app.component';
|
import { AppComponent } from './app/app.component';
|
||||||
|
import { loadRuntimeConfig } from './app/runtime-config';
|
||||||
|
|
||||||
bootstrapApplication(AppComponent, appConfig)
|
(async () => {
|
||||||
.catch((err) => console.error(err));
|
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