Skip to content

Commit d1b95fa

Browse files
authored
chore(www): server headers and fix react code reset (#4284)
1 parent 4e161ae commit d1b95fa

5 files changed

Lines changed: 51 additions & 21 deletions

File tree

apps/www/app/_components/live-component/live-component.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,7 @@
183183
}
184184
}
185185
}
186+
187+
.hidden {
188+
display: none;
189+
}

apps/www/app/_components/live-component/live-components.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,22 @@ const Editor = ({ live, html, id, hidden }: EditorProps) => {
224224
<kbd>{t('live-component.activateB')}</kbd>{' '}
225225
{t('live-component.activateC')}
226226
</div>
227-
{showHTML ? (
228-
<LiveEditor
229-
className={classes.editor}
230-
disabled
231-
code={rawHtml}
232-
language='html'
233-
/>
234-
) : (
235-
<LiveEditor
236-
key={resetCount}
237-
onChange={live.onChange}
238-
className={cl(
239-
classes.editor,
240-
classes['live-editor'],
241-
'live-editor',
242-
)}
243-
/>
244-
)}
227+
<LiveEditor
228+
className={cl(classes.editor, !showHTML && classes.hidden)}
229+
disabled
230+
code={rawHtml}
231+
language='html'
232+
/>
233+
<LiveEditor
234+
key={resetCount}
235+
onChange={live.onChange}
236+
className={cl(
237+
classes.editor,
238+
classes['live-editor'],
239+
'live-editor',
240+
showHTML && classes.hidden,
241+
)}
242+
/>
245243
</div>
246244
</section>
247245
);

apps/www/app/routes/components/component.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'node:fs';
1+
import { existsSync, readFileSync } from 'node:fs';
22
import { createRequire } from 'node:module';
33
import { join } from 'node:path';
44
import {
@@ -49,6 +49,11 @@ export const loader = async ({ params, request }: Route.LoaderArgs) => {
4949
if (!component) {
5050
throw new Response('Not Found', { status: 404, statusText: 'Not Found' });
5151
}
52+
const componentDir = join('app', 'content', 'components', component);
53+
54+
if (!existsSync(componentDir)) {
55+
throw new Response('Not Found', { status: 404, statusText: 'Not Found' });
56+
}
5257

5358
if (
5459
!request.url.includes('code') &&
@@ -72,8 +77,6 @@ export const loader = async ({ params, request }: Route.LoaderArgs) => {
7277

7378
const componentDocs = getComponentDocs(component);
7479

75-
const componentDir = join('app', 'content', 'components', component);
76-
7780
// Extract exported story functions from *.stories.tsx
7881
const storyEntries = extractStories(componentDir);
7982
// Extract exported dodont functions from *.dodont.tsx

apps/www/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ if (DEVELOPMENT) {
3838
express.static('dist/client/assets', { immutable: true, maxAge: '1y' }),
3939
);
4040
app.use(morgan('tiny'));
41+
app.use(
42+
'/.well-known',
43+
express.static('dist/client/.well-known', { maxAge: '1y' }),
44+
);
4145
app.use(express.static('dist/client', { maxAge: '30d' }));
4246
app.use(await import(BUILD_PATH).then((mod) => mod.app));
4347
}

apps/www/server/app.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@ import 'react-router';
22
import { createRequestHandler } from '@react-router/express';
33
import express from 'express';
44

5+
const DEVELOPMENT = process.env.NODE_ENV === 'development';
6+
7+
const connectSrc = [
8+
"'self'",
9+
'https://altinncdn.no',
10+
DEVELOPMENT && 'ws://localhost:*',
11+
]
12+
.filter(Boolean)
13+
.join(' ');
14+
515
export const app = express();
616

717
app.use((req, res, next) => {
18+
res.setHeader('X-Content-Type-Options', 'nosniff');
19+
res.setHeader(
20+
'Strict-Transport-Security',
21+
'max-age=31536000; includeSubDomains',
22+
);
23+
res.setHeader('X-Frame-Options', 'SAMEORIGIN');
24+
res.setHeader(
25+
'Content-Security-Policy-Report-Only',
26+
`default-src 'none';base-uri 'self';script-src 'self' 'unsafe-inline' 'unsafe-eval';style-src 'self' https://altinncdn.no https://siteimproveanalytics.com 'unsafe-inline';font-src 'self' https://altinncdn.no;img-src 'self' data:;connect-src ${connectSrc};frame-ancestors 'self';form-action 'self';manifest-src 'self';`,
27+
);
28+
res.setHeader('Cache-Control', 'max-age');
829
/* Stop TRACE request */
930
if (req.method === 'TRACE') {
1031
res

0 commit comments

Comments
 (0)