Skip to content

Commit

Permalink
fix cors and requestData errors (#59)
Browse files Browse the repository at this point in the history
* fix cors and requestData errors

* add support for static exports
  • Loading branch information
KJES4 authored Jan 9, 2025
1 parent 7ae90f2 commit 3f37533
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
30 changes: 30 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
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;

14 changes: 0 additions & 14 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
/** @type {import('next').NextConfig} */
const nextConfig =
{ async rewrites() {
return [
{
source: '/api/v1/:path*',
destination: 'http://localhost:8080/:path*' // Proxy to Backend
}
]
},
output: 'export'
};

export default nextConfig;
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 9000",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
requestData,
{
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
}
);

console.log('Mint response:', response.data);
} catch (error) {
console.error('Minting failed:', error);
Expand Down

0 comments on commit 3f37533

Please sign in to comment.