-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix cors and requestData errors #59
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
async headers() { | ||
return [ | ||
{ | ||
// matching all API routes | ||
source: "/api/v1/:path*", | ||
headers: [ | ||
{ key: "Access-Control-Allow-Credentials", value: "true" }, | ||
{ key: "Access-Control-Allow-Origin", value: "*" }, | ||
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" }, | ||
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }, | ||
] | ||
} | ||
] | ||
}, | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: '/api/v1/:path*', // Match all routes starting with /api/v1/ | ||
destination: 'http://localhost:8080/api/v1/:path*', // Proxy to backend server | ||
}, | ||
]; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -32,22 +32,21 @@ export default function Home() { | |
|
||
const onMint = async () => { | ||
const requestData = { | ||
asset_name: 'WST', | ||
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex | ||
issuer: mintAccount, | ||
amount: mintTokens, | ||
quantity: mintTokens, | ||
}; | ||
|
||
try { | ||
const response = await axios.post( | ||
'http://localhost:9000/api/tx/programmable-token/issue', | ||
'/api/v1/tx/programmable-token/issue', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks more like a route I would expect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the direct api call not the rewrite. |
||
requestData, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json;charset=utf-8', | ||
}, | ||
} | ||
); | ||
|
||
console.log('Mint response:', response.data); | ||
} catch (error) { | ||
console.error('Minting failed:', error); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the
http://localhost:8080
prefix should be hardcoded. Is it possible to just use the remaining suffix?Granted, I don't know next.js, but this seems off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the nextJS rewrites to an external server work. If I try to replace the hardcoded url with an env variable then I get a 500 internal server error.
Here is the rewrite docs: https://nextjs.org/docs/pages/api-reference/config/next-config-js/rewrites#rewriting-to-an-external-url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me now.
Tested it with the container PR, and the frontend works and pulls the javascript sources.