Skip to content

Commit

Permalink
Merge 4330c7c into 1ef2548
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Dec 3, 2021
2 parents 1ef2548 + 4330c7c commit c5526f8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/S3/S3Router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import supertest from 'supertest'
import { buildURL, createAuthHeaders } from '../../spec/utils'
import { app } from '../server'
import { getBucketURL } from './s3'

const server = supertest(app.getApp())

describe('S3 router', () => {
let fileName: string
let url: string

beforeEach(() => {
fileName = 'aFile'
})

describe('when getting the contents of a file', () => {
beforeEach(() => {
url = `/storage/contents/${fileName}`
})

it('should respond with a cached 301 redirecting to the S3 file', async () => {
await server
.get(buildURL(url))
.set(createAuthHeaders('get', url))
.expect('Location', `${getBucketURL()}/contents/${fileName}`)
.expect('Cache-Control', 'public,max-age=31536000,immutable')
.expect(301)
})
})

describe('when getting the information of a file', () => {
beforeEach(() => {
url = `/storage/contents/${fileName}`
})

it('should respond with a cached 301 redirecting to the S3 file', async () => {
await server
.get(buildURL(url))
.set(createAuthHeaders('head', url))
.expect('Location', `${getBucketURL()}/contents/${fileName}`)
.expect('Cache-Control', 'public,max-age=31536000,immutable')
.expect(301)
})
})
})
5 changes: 5 additions & 0 deletions src/S3/S3Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class S3Router extends Router {
* Get an asset file by file id (also contains items)
*/
this.router.get('/storage/contents/:filename', this.handleContents)

/**
* Get the response headers for a file
*/
this.router.head('/storage/contents/:filename', this.handleContents)
}

private buildRedirectUrl(model: S3Model, filename: string) {
Expand Down

0 comments on commit c5526f8

Please sign in to comment.