Skip to content

Commit

Permalink
fix: gitpod cors issue (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshanzel authored Oct 3, 2024
1 parent 40460d8 commit f922155
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
5 changes: 4 additions & 1 deletion packages/shared/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const apiUrl = process.env.NEXT_PUBLIC_API_URL;
export const apiUrl =
process.env.NEXT_PUBLIC_DOMAIN === 'localhost'
? '/api'
: process.env.NEXT_PUBLIC_API_URL;

export const graphqlUrl = `${apiUrl}/graphql`;

Expand Down
50 changes: 31 additions & 19 deletions packages/webapp/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,38 @@ module.exports = {
env: {
CURRENT_VERSION: version,
},
rewrites: () => [
{
source: '/api/sitemaps/:path*',
destination: `${process.env.NEXT_PUBLIC_API_URL}/sitemaps/:path*`,
},
{
source: '/search',
destination: '/search/:provider',
has: [
{
type: 'query',
key: 'provider'
}
]
},
{
source: '/search',
destination: '/search/posts'
rewrites: () => {
const rewrites = [
{
source: '/api/sitemaps/:path*',
destination: `${process.env.NEXT_PUBLIC_API_URL}/sitemaps/:path*`,
},
{
source: '/search',
destination: '/search/:provider',
has: [
{
type: 'query',
key: 'provider'
}
]
},
{
source: '/search',
destination: '/search/posts'
}
];

// to support GitPod environment and avoid CORS issues, we need to proxy the API requests
if (process.env.NEXT_PUBLIC_DOMAIN === 'localhost') {
rewrites.unshift({
source: '/api/:path*',
destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`,
});
}
],

return rewrites;
},
redirects: () => {
return [
{
Expand Down

0 comments on commit f922155

Please sign in to comment.