File tree Expand file tree Collapse file tree
java/com/ontario/program/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8080 - name : Build for production
8181 run : npm run build
8282 env :
83- VITE_API_BASE_URL : /api
83+ VITE_API_BASE_URL : https://${{ env.BACKEND_APP_NAME }}.azurewebsites.net /api
8484
8585 - name : Upload frontend artifact
8686 uses : actions/upload-artifact@v4
@@ -126,6 +126,7 @@ jobs:
126126 --settings \
127127 SPRING_PROFILES_ACTIVE=azuresql \
128128 SPRING_DATASOURCE_URL="jdbc:sqlserver://${{ env.SQL_SERVER_NAME }}.database.windows.net:1433;database=${{ env.SQL_DATABASE_NAME }};encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=60;authentication=ActiveDirectoryManagedIdentity;msiClientId=${{ vars.SQL_IDENTITY_CLIENT_ID }};connectRetryCount=3;connectRetryInterval=10;" \
129+ APP_CORS_ALLOWED_ORIGIN="https://${{ env.FRONTEND_APP_NAME }}.azurewebsites.net" \
129130 --only-show-errors
130131
131132 - name : Restart App Service
Original file line number Diff line number Diff line change 1+ package com .ontario .program .config ;
2+
3+ import org .springframework .beans .factory .annotation .Value ;
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .web .cors .CorsConfiguration ;
7+ import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
8+ import org .springframework .web .filter .CorsFilter ;
9+
10+ /**
11+ * CORS configuration — allows the frontend origin to call the API
12+ * when frontend and backend are on different App Service instances.
13+ */
14+ @ Configuration
15+ public class CorsConfig {
16+
17+ @ Value ("${app.cors.allowed-origin:http://localhost:3000}" )
18+ private String allowedOrigin ;
19+
20+ @ Bean
21+ public CorsFilter corsFilter () {
22+ final CorsConfiguration config = new CorsConfiguration ();
23+ config .addAllowedOrigin (allowedOrigin );
24+ config .addAllowedHeader ("*" );
25+ config .addAllowedMethod ("*" );
26+ config .setAllowCredentials (true );
27+ config .setMaxAge (3600L );
28+
29+ final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
30+ source .registerCorsConfiguration ("/api/**" , config );
31+ return new CorsFilter (source );
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ server:
4646
4747app :
4848 cors :
49- allowed-origin : http://localhost:3000
49+ allowed-origin : ${APP_CORS_ALLOWED_ORIGIN: http://localhost:3000}
5050
5151logging :
5252 level :
Original file line number Diff line number Diff line change 11import axios from 'axios' ;
22
33const api = axios . create ( {
4- baseURL : '/api' ,
4+ baseURL : import . meta . env . VITE_API_BASE_URL || '/api' ,
55 headers : {
66 'Content-Type' : 'application/json' ,
77 } ,
You can’t perform that action at this time.
0 commit comments