-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Solve cross-domain issues (#153)
- Loading branch information
1 parent
df445dd
commit 44d3948
Showing
4 changed files
with
47 additions
and
8 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,9 @@ | ||
import React from 'react'; | ||
|
||
export default function ModelEditorLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return <>{children}</>; | ||
} |
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { ModelEditor } from '../components/ModelEditor'; | ||
|
||
const ModelEditorPage = ({ searchParams }: { searchParams: { model?: string } }) => { | ||
const initialValue = searchParams.model ? decodeURIComponent(searchParams.model) : ''; | ||
export default function ModelEditorPage() { | ||
const [initialValue, setInitialValue] = useState(''); | ||
|
||
useEffect(() => { | ||
const params = new URLSearchParams(window.location.search); | ||
const modelParam = params.get('model'); | ||
if (modelParam) { | ||
setInitialValue(decodeURIComponent(modelParam)); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div style={{ width: '100%', height: '100vh' }}> | ||
<ModelEditor initialValue={initialValue} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ModelEditorPage; | ||
} |
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,18 @@ | ||
import { NextResponse } from 'next/server'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
export function middleware(request: NextRequest) { | ||
const response = NextResponse.next(); | ||
const origin = request.headers.get('origin') || '*'; | ||
|
||
response.headers.set('Access-Control-Allow-Origin', origin); | ||
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); | ||
response.headers.set('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); | ||
response.headers.set('Access-Control-Allow-Credentials', 'true'); | ||
|
||
return response; | ||
} | ||
|
||
export const config = { | ||
matcher: '/model-editor/:path*', | ||
}; |