Skip to content

Commit 8f5b61d

Browse files
[PRMP-919] Update nginx.conf (#914)
Co-authored-by: adamwhitingnhs <[email protected]>
1 parent 1b235d5 commit 8f5b61d

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

.github/workflows/base-cypress-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
npm install --legacy-peer-deps
5858
working-directory: ./app
5959

60+
- name: Copy main.html to index.html for serve compatibility
61+
run: cp ./app/build/main.html ./app/build/index.html
62+
6063
- name: Cypress run
6164
uses: cypress-io/github-action@v6
6265
with:

app/docker/nginx.conf

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ http {
2828
add_header X-Permitted-Cross-Domain-Policies "none" always;
2929

3030
location / {
31-
index index.html index.htm;
32-
try_files $uri $uri/ /index.html$is_args$args;
33-
34-
add_header Cache-Control "private, max-age=63072000" always;
35-
add_header Pragma "private, max-age=63072000" always;
31+
index main.html;
32+
try_files $uri $uri/ /main.html$is_args$args;
3633
}
3734

3835
location /pdfjs/ {
3936
add_header Content-Security-Policy "default-src 'none'; frame-ancestors 'self'; img-src 'self' blob: data:; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self' blob: https:;" always;
4037
add_header Permissions-Policy "fullscreen=()" always;
4138
add_header X-Frame-Options "SAMEORIGIN" always;
42-
try_files $uri $uri/ /index.html$is_args$args;
39+
try_files $uri $uri/;
4340
}
4441
}
4542
}

app/index.html renamed to app/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
<body>
5454
<noscript>You need to enable JavaScript to run this app.</noscript>
5555
<div id="root"></div>
56-
<script type="module" src="/src/index.tsx"></script>
56+
<script type="module" src="/src/main.tsx"></script>
5757
</body>
5858
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
3-
import './styles/index.css';
3+
import './styles/main.css';
44
import App from './App';
55
import 'pdfjs-viewer-element';
66
import PdfjsViewerElement from 'pdfjs-viewer-element';

app/vite.config.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ import svgr from 'vite-plugin-svgr';
44
import commonjs from 'vite-plugin-commonjs';
55
import eslint from 'vite-plugin-eslint';
66

7+
// Custom plugin to handle SPA fallback to main.html
8+
const spaFallbackPlugin = () => {
9+
const fallbackMiddleware = (req: any, res: any, next: any) => {
10+
// Only handle GET requests that look like routes (not files)
11+
if (
12+
req.method === 'GET' &&
13+
req.url &&
14+
!req.url.startsWith('/assets/') &&
15+
!req.url.startsWith('/src/') &&
16+
!req.url.startsWith('/@') &&
17+
!req.url.includes('.') &&
18+
req.url !== '/main.html' &&
19+
req.headers.accept?.includes('text/html')
20+
) {
21+
req.url = '/main.html';
22+
}
23+
next();
24+
};
25+
26+
return {
27+
name: 'spa-fallback-main-html',
28+
configureServer(server: any) {
29+
server.middlewares.use(fallbackMiddleware);
30+
},
31+
configurePreviewServer(server: any) {
32+
server.middlewares.use(fallbackMiddleware);
33+
}
34+
};
35+
};
36+
737
// https://vitejs.dev/config/
838
export default defineConfig({
939
base: '/',
@@ -19,9 +49,17 @@ export default defineConfig({
1949
},
2050
}),
2151
eslint(),
52+
spaFallbackPlugin()
2253
],
54+
preview: {
55+
port: 3000,
56+
host: true,
57+
},
2358
build: {
2459
commonjsOptions: { transformMixedEsModules: true },
2560
chunkSizeWarningLimit: 1024,
26-
},
61+
rollupOptions: {
62+
input: './main.html',
63+
},
64+
}
2765
});

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sonar.python.coverage.reportPaths=lambdas/coverage.xml
1414
sonar.sources=lambdas/,app/src/
1515
sonar.tests=lambdas/tests/,app/src/
1616

17-
sonar.exclusions=**/*.test.tsx,app/src/helpers/test/**,**/TestPanel.tsx,**/lambdas/scripts/**,**/*.test.ts,lambdas/tests/**,**/conftest.py,app/react-build-env-checker.js,app/public/*,app/src/index.tsx
17+
sonar.exclusions=**/*.test.tsx,app/src/helpers/test/**,**/TestPanel.tsx,**/lambdas/scripts/**,**/*.test.ts,lambdas/tests/**,**/conftest.py,app/react-build-env-checker.js,app/public/*,app/src/main.tsx
1818
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
1919

2020
# Encoding of the source code. Default is default system encoding

0 commit comments

Comments
 (0)