mirror of
https://github.com/yude-jp/yude.jp
synced 2025-01-22 11:20:10 +09:00
Using next.config.js rewrite for UUID validation
This commit is contained in:
parent
b95c6b4cd5
commit
ee913461f1
@ -1,5 +1,18 @@
|
||||
const nextTranslate = require('next-translate')
|
||||
|
||||
const rewrites = async () => {
|
||||
return [
|
||||
{
|
||||
source: '/minecraft/players/:uuid(\[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})',
|
||||
destination: '/minecraft/players/:uuid'
|
||||
},
|
||||
{
|
||||
source: '/minecraft/players/:uuid',
|
||||
destination: '/404'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = nextTranslate({
|
||||
i18n: {
|
||||
locales: ['ja', 'en'],
|
||||
@ -29,4 +42,5 @@ module.exports = nextTranslate({
|
||||
}
|
||||
]
|
||||
},
|
||||
rewrites,
|
||||
})
|
@ -1,15 +0,0 @@
|
||||
import Players from './Players'
|
||||
import WrongUUID from './WrongUUID'
|
||||
|
||||
function App (props) {
|
||||
const uuid = props;
|
||||
const regex = "[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
||||
|
||||
if (uuid.uuid.match(regex)) {
|
||||
return <Players uuid={uuid.uuid} />
|
||||
} else {
|
||||
return <WrongUUID />
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
@ -8,9 +8,9 @@ import useTranslation from 'next-translate/useTranslation'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
// Data fetching
|
||||
import UUIDCheck from '../../components/Minecraft/UUIDCheck'
|
||||
import Players from '../../components/Minecraft/Players'
|
||||
|
||||
export default function Players() {
|
||||
export default function UUID() {
|
||||
const router = useRouter()
|
||||
const { locale, locales, defaultLocale, pathname } = router
|
||||
const { t, lang } = useTranslation("index")
|
||||
@ -19,7 +19,7 @@ export default function Players() {
|
||||
return (
|
||||
<>
|
||||
<Layout title={t('home')}>
|
||||
<UUIDCheck uuid={uuid} />
|
||||
<Players uuid={uuid} />
|
||||
</Layout>
|
||||
</>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user