Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
OX App Suite
Core
ui-middleware
Commits
9b33933e
Commit
9b33933e
authored
3 years ago
by
richard.petersen
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Binary handling without .buffer()
parent
458e66c6
No related branches found
Branches containing commit
No related tags found
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
spec/file_caching_test.js
+21
-3
21 additions, 3 deletions
spec/file_caching_test.js
spec/media/image.png
+0
-0
0 additions, 0 deletions
spec/media/image.png
src/files.js
+1
-1
1 addition, 1 deletion
src/files.js
with
22 additions
and
4 deletions
spec/file_caching_test.js
+
21
−
3
View file @
9b33933e
...
...
@@ -3,6 +3,10 @@ import mockfs from 'mock-fs'
import
request
from
'
supertest
'
import
{
createApp
}
from
'
../src/createApp
'
import
{
createMockServer
,
generateSimpleViteManifest
,
getRandomPort
}
from
'
./util.js
'
import
fs
from
'
fs
'
const
image
=
fs
.
readFileSync
(
'
./spec/media/image.png
'
)
const
imageStat
=
fs
.
statSync
(
'
./spec/media/image.png
'
)
describe
(
'
File caching service
'
,
()
=>
{
let
app
...
...
@@ -35,15 +39,23 @@ describe('File caching service', () => {
isEntry
:
true
,
imports
:
[
'
example.js
'
],
css
:
[
'
main.css
'
]
}
},
'
image.png
'
:
{}
}),
'
/example.js
'
:
(
req
,
res
)
=>
res
.
setHeader
(
'
content-type
'
,
'
application/javascript
'
).
status
(
200
).
send
(
'
this is example
'
),
'
/test.txt
'
:
(
req
,
res
)
=>
res
.
setHeader
(
'
content-type
'
,
'
text/plain
'
).
status
(
200
).
send
(
'
this is test
'
),
'
/index.html.js
'
:
(
req
,
res
)
=>
res
.
setHeader
(
'
content-type
'
,
'
application/javascript
'
).
status
(
200
).
send
(
'
this is index.html.js
'
),
'
/index.html
'
:
(
req
,
res
)
=>
res
.
setHeader
(
'
content-type
'
,
'
text/html
'
).
status
(
200
).
send
(
'
<html><head></head><body>it
\'
s me</body></html>
'
),
'
/main.css
'
:
(
req
,
res
)
=>
res
.
setHeader
(
'
content-type
'
,
'
text/css
'
).
status
(
200
).
send
(
'
.foo { color: #000; }
'
),
'
/favicon.ico
'
:
'
not really a favicon, though
'
'
/favicon.ico
'
:
'
not really a favicon, though
'
,
'
/image.png
'
:
(
req
,
res
)
=>
{
// need to do this like this, because jest messes up file system within tests
res
.
set
({
'
Content-Type
'
:
'
image/png
'
,
'
Content-Length
'
:
imageStat
.
size
})
res
.
end
(
image
)
}
})
await
request
(
app
).
get
(
'
/ready
'
)
})
...
...
@@ -96,4 +108,10 @@ describe('File caching service', () => {
const
response
=
await
request
(
app
).
get
(
'
/unknown-file.txt
'
)
expect
(
response
.
statusCode
).
toBe
(
404
)
})
it
(
'
serves binary files
'
,
async
()
=>
{
const
response
=
await
request
(
app
).
get
(
'
/image.png
'
)
expect
(
response
.
statusCode
).
toBe
(
200
)
expect
(
response
.
body
.
length
===
imageStat
.
size
)
})
})
This diff is collapsed.
Click to expand it.
spec/media/image.png
0 → 100644
+
0
−
0
View file @
9b33933e
10.1 KiB
This diff is collapsed.
Click to expand it.
src/files.js
+
1
−
1
View file @
9b33933e
...
...
@@ -9,7 +9,7 @@ const logger = getLogger()
async
function
fetchData
(
path
,
baseUrl
)
{
const
response
=
await
fetch
(
new
URL
(
path
,
baseUrl
))
if
(
!
response
.
ok
)
throw
new
Error
(
`Error fetching file:
${
path
}
`
)
const
content
=
await
response
.
text
()
const
content
=
Buffer
.
from
(
await
response
.
arrayBuffer
()
)
const
sha256Sum
=
crypto
.
createHash
(
'
sha256
'
).
update
(
content
).
digest
(
'
base64
'
)
return
[
path
,
{
'
content-type
'
:
response
.
headers
.
get
(
'
content-type
'
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment