Skip to content

Commit

Permalink
feat: add nginx rewrites (#5580)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Jul 31, 2023
1 parent dee9f3f commit 9f67d43
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 0 deletions.
5 changes: 5 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';

import * as nextConstants from './next.constants.mjs';
import * as nextRewrites from './next.rewrites.mjs';

/** @type {import('next').NextConfig} */
const nextConfig = {
// This configures all the Next.js rewrites
rewrites: nextRewrites.rewrites,
// This configures all Next.js redirects
redirects: nextRewrites.redirects,
// We intentionally disable Next.js's built-in i18n support
// as we dom have our own i18n and internationalisation engine
i18n: null,
Expand Down
205 changes: 205 additions & 0 deletions next.rewrites.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
'use strict';

/**
* These are external redirects that happen before we check dynamic routes and rewrites
* These are sourced originally from https://github.com/nodejs/build/blob/main/ansible/www-standalone/resources/config/nodejs.org?plain=1
* and were then converted to Next.js rewrites. Note that only relevant rewrites were added and some were modified to match Next.js's syntax
*
* @type {import('next').NextConfig['redirects']}
*/
const redirects = async () => [
{
source: '/changelog.html',
destination: 'https://github.com/nodejs/node/blob/HEAD/CHANGELOG.md',
permanent: true,
},
{
source: '/contribute/accepting_contributions.html',
destination: 'https://github.com/nodejs/dev-policy',
permanent: true,
},
{
source: '/about/releases',
destination: 'https://github.com/nodejs/release#release-schedule',
permanent: true,
},
{
source: '/about/security',
destination:
'https://github.com/nodejs/node/blob/HEAD/SECURITY.md#security',
permanent: true,
},
{
source: '/advisory-board',
destination: 'https://github.com/nodejs/TSC',
permanent: true,
},
{
source: '/about/advisory-board',
destination: 'https://github.com/nodejs/TSC',
permanent: true,
},
{
source: '/about/organization',
destination: 'https://github.com/nodejs/TSC',
permanent: true,
},
{
source: '/about/organization/tsc-meetings',
destination: 'https://github.com/nodejs/TSC/tree/HEAD/meetings',
permanent: true,
},
{
source: '/calendar',
destination:
'https://calendar.google.com/calendar/embed?src=nodejs.org_nr77ama8p7d7f9ajrpnu506c98%40group.calendar.google.com',
permanent: true,
},
{
source: '/calendar.ics',
destination:
'https://calendar.google.com/calendar/ical/nodejs.org_nr77ama8p7d7f9ajrpnu506c98%40group.calendar.google.com/public/basic.ics',
permanent: true,
},
{
source: '/(en|uk|)/foundation',
destination: 'https://foundation.nodejs.org/',
permanent: true,
},
{
source: '/(en|uk|)/foundation/case-studies',
destination: 'https://openjsf.org/projects',
permanent: true,
},
{
source: '/(en|uk|)/foundation/members',
destination: 'https://openjsf.org/about/members',
permanent: true,
},
{
source: '/(en|uk|)/foundation/board',
destination: 'https://openjsf.org/about/governance',
permanent: true,
},
{
source: '/(en|uk|)/foundation/tsc',
destination: 'https://github.com/nodejs/TSC',
permanent: true,
},
{
source: '/(en|uk|)/foundation/certification',
destination: 'https://openjsf.org/certification',
permanent: true,
},
{
source: '/(en|uk|)/foundation/in-the-news',
destination: 'https://openjsf.org',
permanent: true,
},
{
source: '/(en|uk|)/foundation/announcements',
destination: 'https://openjsf.org/blog',
permanent: true,
},
{
source: '/(en|uk|)/foundation/education',
destination: 'https://openjsf.org/certification',
permanent: true,
},
{
source: '/(en|uk|)/foundation/members.html',
destination: 'https://openjsf.org/about/members',
permanent: true,
},
];

/**
* These are rewrites that happen before we check dynamic routes and after we check regular redirects
* These should be used either for internal or external rewrite rules (like NGINX, for example)
* These are sourced originally from https://github.com/nodejs/build/blob/main/ansible/www-standalone/resources/config/nodejs.org?plain=1
* and were then converted to Next.js rewrites. Note that only relevant rewrites were added and some were modified to match Next.js's syntax
*
* @type {import('next').NextConfig['rewrites']}
*/
const rewrites = async () => ({
afterFiles: [
{
source: '/index.html',
destination: '/',
},
{
source: '/api.html',
destination: '/api/',
},
{
source: '/community',
destination: '/en/get-involved',
},
{
source: '/contribute',
destination: '/en/get-involved',
},
{
source: '/contribute/becoming_collaborator.html',
destination: '/en/get-involved',
},
{
source: '/contribute/code_contributions',
destination: '/en/get-involved',
},
{
source: '/contribute/code_contributions/workflow.html',
destination: '/en/get-involved',
},
{
source: '/documentation(.*)',
destination: '/en/docs',
},
{
source: '/about',
destination: '/en/about',
},
{
source: '/about/trademark',
destination: '/en/about/trademark',
},
{
source: '/blog/:path*',
destination: '/en/blog/:path*',
},
{
source: '/(atom|feed|rss).xml',
destination: '/en/feed/blog.xml',
},
{
source: '/feed',
destination: '/en/feed/blog.xml',
},
{
source: '/feed/release',
destination: '/en/feed/releases.xml',
},
{
source: '/feed/vulnerability',
destination: '/en/feed/vulnerability.xml',
},
{
source: '/(static/|)favicon.ico',
destination: '/static/images/favicons/favicon.png',
},
{
source: '/(static/|)favicon.png',
destination: '/static/images/favicons/favicon.png',
},
{
source: '/(static/|)apple-touch-icon(.*).png',
destination: '/static/images/favicons/favicon.png',
},
{
source: '/logos/:path*',
destination: '/static/images/logos/:path*',
},
],
});

export { rewrites, redirects };

1 comment on commit 9f67d43

@vercel
Copy link

@vercel vercel bot commented on 9f67d43 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nodejs-org-stories – ./

nodejs-org-stories-openjs.vercel.app
nodejs-org-stories-git-main-openjs.vercel.app
nodejs-org-storybook.vercel.app

Please sign in to comment.