Skip to content

Commit 876ed1d

Browse files
feat: add redirects structure (#1154)
1 parent d8ac7f4 commit 876ed1d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- 🗂 Path Mapping — Import components or images using the `@` prefix
4242
- 🔐 CSP — Content Security Policy for enhanced security (default minimal policy)
4343
- 🧳 T3 Env — Type-safe environment variables
44+
- 🪧 Redirects — Easily add redirects to your application
4445

4546
## Quick Start
4647

@@ -110,7 +111,10 @@ List of websites that started off with Next.js TypeScript Starter:
110111
- `pnpm start` — Starts the application in production mode.
111112
- `pnpm type-check` — Validate code using TypeScript compiler.
112113
- `pnpm lint` — Runs ESLint for all files in the `src` directory.
114+
- `pnpm lint:fix` — Runs ESLint fix for all files in the `src` directory.
113115
- `pnpm format` — Runs Prettier for all files in the `src` directory.
116+
- `pnpm format:check` — Check Prettier list of files that need to be formatted.
117+
- `pnpm format:ci` — Prettier check for CI.
114118

115119
### Path Mapping
116120

@@ -134,6 +138,16 @@ We use [T3 Env](https://env.t3.gg/) to manage environment variables. Create a `.
134138

135139
When adding additional environment variables, the schema in `./src/lib/env/client.ts` or `./src/lib/env/server.ts` should be updated accordingly.
136140

141+
### Redirects
142+
143+
To add redirects, update the `redirects` array in `./redirects.ts`. It's typed, so you'll get autocompletion for the properties.
144+
145+
### CSP (Content Security Policy)
146+
147+
The Content Security Policy (CSP) is a security layer that helps to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection attacks. The CSP is implemented in the `next.config.ts` file.
148+
149+
It contains a default and minimal policy that you can customize to fit your application needs. It's a foundation to build upon.
150+
137151
## License
138152

139153
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for more information.

next.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { NextConfig } from 'next';
33
import './src/lib/env/client';
44
import './src/lib/env/server';
55

6+
import { redirects } from './redirects';
7+
68
/**
79
* CSPs that we're not adding (as it can change from project to project):
810
* frame-src, connect-src, script-src, child-src, style-src, worker-src, font-src, media-src, and img-src
@@ -57,6 +59,9 @@ const nextConfig: NextConfig = {
5759
},
5860
];
5961
},
62+
async redirects() {
63+
return redirects;
64+
},
6065
reactStrictMode: true,
6166
};
6267

redirects.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { type Redirect } from 'next/dist/lib/load-custom-routes';
2+
3+
export const redirects: Redirect[] = [
4+
{
5+
source: '/index',
6+
destination: '/',
7+
permanent: true,
8+
},
9+
];

0 commit comments

Comments
 (0)