-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the 1-click-bom.tsv file accessible to the 1-click-bom extension.
The 1-click-bom extension tries loading the `1-click-BOM.tsv` file by `GET`ing `[...projecURL]/1-click-BOM.tsx`. But we have the file in the processor (or later on s3) so using this approach will let us control the actual `1-click-BOM.tsv` file URL without re-modifying the extension.
- Loading branch information
1 parent
d7411d4
commit 643d0ea
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// middleware.ts | ||
import { NextResponse } from 'next/server' | ||
|
||
// The redirection between the different proxied services corrupts SSL somehow. | ||
// As a workaround we redirect using http:// and nginx will automatically upgrade it to https://. | ||
const sslWorkaround = url => { | ||
url = new URL(url) | ||
url.protocol = 'http:' | ||
return url.toString().slice(0, -1) // remove the trailing slash | ||
} | ||
|
||
const No_SSL_KITSPACE_PROCESSOR_URL = sslWorkaround( | ||
process.env.KITSPACE_PROCESSOR_URL, | ||
) | ||
|
||
/* | ||
* Make the 1-click-bom.tsv file accessible to the 1-click-bom extension. | ||
* We can't use the following snippet `next.config.js` redirects: it generates the redirect URLs during the build time of the container. | ||
* But the KITSPACE_PROCESSOR_URL is only available at runtime. | ||
{ | ||
source: '/:user/:repo/:project/1-click-BOM.tsv', | ||
destination: `${process.env.KITSPACE_PROCESSOR_URL}/files/:user/:repo/HEAD/:project/1-click-BOM.tsv`, | ||
permanent: true, | ||
} | ||
*/ | ||
export function middleware(request) { | ||
// We are using the pattern because simply using ':user/:repo/:project/1-click-BOM.tsv' matches `/static/` files as well. | ||
const matches = request.nextUrl.pathname.match( | ||
/^\/(?<user>.+)\/(?<repo>.+)\/(?<project>.+)\/(?:1-click-BOM.tsv)$/, | ||
) | ||
if (matches) { | ||
const { user, repo, project } = matches.groups | ||
return NextResponse.redirect( | ||
`${No_SSL_KITSPACE_PROCESSOR_URL}/files/${user}/${repo}/HEAD/${project}/1-click-BOM.tsv`, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters