27 lines
587 B
TypeScript
27 lines
587 B
TypeScript
|
import * as React from 'react'
|
||
|
import type { GetServerSideProps } from 'next'
|
||
|
|
||
|
interface RoomProps {
|
||
|
id?: string
|
||
|
}
|
||
|
|
||
|
export default function RandomRoomPage({ id }: RoomProps): JSX.Element {
|
||
|
return <div>Should have routed to room: {id}</div>
|
||
|
}
|
||
|
|
||
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||
|
// Generate random id
|
||
|
const id = Date.now().toString()
|
||
|
|
||
|
// Route to a room with that id
|
||
|
context.res.setHeader('Location', `/r/${id}`)
|
||
|
context.res.statusCode = 307
|
||
|
|
||
|
// Return id (though it shouldn't matter)
|
||
|
return {
|
||
|
props: {
|
||
|
id,
|
||
|
},
|
||
|
}
|
||
|
}
|