mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-03 12:05:57 +01:00
🗑️ Remove index and slug pages and add redirect to /board
This commit is contained in:
@@ -13,4 +13,11 @@ module.exports = withBundleAnalyzer({
|
||||
output: 'standalone',
|
||||
i18n,
|
||||
transpilePackages: ['@jellyfin/sdk'],
|
||||
redirects: async () => [
|
||||
{
|
||||
source: '/',
|
||||
destination: '/board',
|
||||
permanent: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import { setCookie } from 'cookies-next';
|
||||
import fs from 'fs';
|
||||
import { GetServerSidePropsContext } from 'next';
|
||||
import path from 'path';
|
||||
|
||||
import { LoadConfigComponent } from '../components/Config/LoadConfig';
|
||||
import { Dashboard } from '../components/Dashboard/Dashboard';
|
||||
import Layout from '../components/layout/Layout';
|
||||
import { useInitConfig } from '../config/init';
|
||||
import { getFallbackConfig } from '../tools/config/getFallbackConfig';
|
||||
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
||||
import { getServerSideTranslations } from '../tools/server/getServerSideTranslations';
|
||||
import { dashboardNamespaces } from '../tools/server/translation-namespaces';
|
||||
import { ConfigType } from '../types/config';
|
||||
import { DashboardServerSideProps } from '../types/dashboardPageType';
|
||||
|
||||
export async function getServerSideProps({
|
||||
req,
|
||||
res,
|
||||
locale,
|
||||
query,
|
||||
}: GetServerSidePropsContext): Promise<{ props: DashboardServerSideProps }> {
|
||||
const configName = query.slug as string;
|
||||
const configPath = path.join(process.cwd(), 'data/configs', `${configName}.json`);
|
||||
const configExists = fs.existsSync(configPath);
|
||||
|
||||
const translations = await getServerSideTranslations(dashboardNamespaces, locale, req, res);
|
||||
|
||||
if (!configExists) {
|
||||
// Redirect to 404
|
||||
res.writeHead(301, { Location: '/404' });
|
||||
res.end();
|
||||
return {
|
||||
props: {
|
||||
config: getFallbackConfig() as unknown as ConfigType,
|
||||
configName,
|
||||
...translations,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const config = await getFrontendConfig(configName as string);
|
||||
setCookie('config-name', configName, {
|
||||
req,
|
||||
res,
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
sameSite: 'strict',
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
configName,
|
||||
config,
|
||||
...translations,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function HomePage({ config: initialConfig }: DashboardServerSideProps) {
|
||||
useInitConfig(initialConfig);
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Dashboard />
|
||||
<LoadConfigComponent />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
import { getCookie, setCookie } from 'cookies-next';
|
||||
import fs from 'fs';
|
||||
import { GetServerSidePropsContext } from 'next';
|
||||
import { MainLayout } from '~/components/layout/main';
|
||||
|
||||
import { LoadConfigComponent } from '../components/Config/LoadConfig';
|
||||
import { Dashboard } from '../components/Dashboard/Dashboard';
|
||||
import Layout from '../components/layout/Layout';
|
||||
import { useInitConfig } from '../config/init';
|
||||
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
||||
import { getServerSideTranslations } from '../tools/server/getServerSideTranslations';
|
||||
import { dashboardNamespaces } from '../tools/server/translation-namespaces';
|
||||
import { DashboardServerSideProps } from '../types/dashboardPageType';
|
||||
|
||||
export async function getServerSideProps({
|
||||
req,
|
||||
res,
|
||||
locale,
|
||||
}: GetServerSidePropsContext): Promise<{ props: DashboardServerSideProps }> {
|
||||
// Get all the configs in the /data/configs folder
|
||||
// All the files that end in ".json"
|
||||
const configs = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json'));
|
||||
|
||||
if (
|
||||
!configs.every(
|
||||
(config) => JSON.parse(fs.readFileSync(`./data/configs/${config}`, 'utf8')).schemaVersion
|
||||
)
|
||||
) {
|
||||
// Replace the current page with the migrate page but don't redirect
|
||||
// This is to prevent the user from seeing the redirect
|
||||
res.writeHead(302, {
|
||||
Location: '/migrate',
|
||||
});
|
||||
res.end();
|
||||
|
||||
return { props: {} as DashboardServerSideProps };
|
||||
}
|
||||
|
||||
let configName = getCookie('config-name', { req, res });
|
||||
if (!configName) {
|
||||
setCookie('config-name', 'default', {
|
||||
req,
|
||||
res,
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
sameSite: 'strict',
|
||||
});
|
||||
configName = 'default';
|
||||
}
|
||||
|
||||
const translations = await getServerSideTranslations(dashboardNamespaces, locale, req, res);
|
||||
const config = await getFrontendConfig(configName as string);
|
||||
|
||||
return {
|
||||
props: {
|
||||
configName: configName as string,
|
||||
config,
|
||||
...translations,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function HomePage({ config: initialConfig }: DashboardServerSideProps) {
|
||||
useInitConfig(initialConfig);
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Dashboard />
|
||||
<LoadConfigComponent />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user