Skip to content

Commit 1f3ba11

Browse files
committed
fix msw warnings and place the images not in a root dir during dev
1 parent 4fe6e44 commit 1f3ba11

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
.DS_store
33

4-
/data
54
/build
65
/server-build
76
.env
@@ -16,6 +15,7 @@ node_modules
1615
/playwright/.cache/
1716
/tests/fixtures/email/
1817
/tests/fixtures/uploaded/
18+
/tests/fixtures/openimg/
1919
/coverage
2020

2121
/other/cache.db

app/routes/resources+/images.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { getImgResponse } from 'openimg/node'
2-
import { type Route } from './+types/images.ts'
32
import { getDomainUrl } from '#app/utils/misc.tsx'
3+
import { type Route } from './+types/images.ts'
44

55
export async function loader({ request }: Route.LoaderArgs) {
66
const domain = getDomainUrl(request)
77
const headers = new Headers()
88
headers.set('Cache-Control', 'public, max-age=31536000, immutable')
99
return getImgResponse(request, {
1010
headers,
11-
allowlistedOrigins: [domain, process.env.AWS_ENDPOINT_URL_S3],
11+
allowlistedOrigins: [domain, process.env.AWS_ENDPOINT_URL_S3].filter(
12+
Boolean,
13+
),
1214
cacheFolder:
13-
process.env.NODE_ENV === 'production' ? '/data/images' : './data/images',
15+
process.env.NODE_ENV === 'production'
16+
? '/data/images'
17+
: './tests/fixtures/openimg',
1418
getImgSource: ({ params }) => {
1519
if (params.src.startsWith('/resources')) {
1620
// Fetch image from resource endpoint

tests/mocks/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ server.listen({
1919
if (request.url.includes('.sentry.io')) {
2020
return
2121
}
22+
// Do not print warnings on unhandled requests to ourselves
23+
if (request.url.includes(`localhost:${process.env.PORT}`)) {
24+
return
25+
}
2226
// Print the regular MSW unhandled request warning otherwise.
2327
print.warning()
2428
},

0 commit comments

Comments
 (0)