Skip to content

Commit

Permalink
feat: add redirects structure (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroschmitz authored Dec 20, 2024
1 parent d8ac7f4 commit 876ed1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- 🗂 Path Mapping — Import components or images using the `@` prefix
- 🔐 CSP — Content Security Policy for enhanced security (default minimal policy)
- 🧳 T3 Env — Type-safe environment variables
- 🪧 Redirects — Easily add redirects to your application

## Quick Start

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

### Path Mapping

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

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

### Redirects

To add redirects, update the `redirects` array in `./redirects.ts`. It's typed, so you'll get autocompletion for the properties.

### CSP (Content Security Policy)

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.

It contains a default and minimal policy that you can customize to fit your application needs. It's a foundation to build upon.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for more information.
5 changes: 5 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { NextConfig } from 'next';
import './src/lib/env/client';
import './src/lib/env/server';

import { redirects } from './redirects';

/**
* CSPs that we're not adding (as it can change from project to project):
* frame-src, connect-src, script-src, child-src, style-src, worker-src, font-src, media-src, and img-src
Expand Down Expand Up @@ -57,6 +59,9 @@ const nextConfig: NextConfig = {
},
];
},
async redirects() {
return redirects;
},
reactStrictMode: true,
};

Expand Down
9 changes: 9 additions & 0 deletions redirects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { type Redirect } from 'next/dist/lib/load-custom-routes';

export const redirects: Redirect[] = [
{
source: '/index',
destination: '/',
permanent: true,
},
];

0 comments on commit 876ed1d

Please sign in to comment.