├── .gitattributes ├── .gitignore ├── README.md ├── package-lock.json ├── package.json └── pages └── index.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | .env 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🦘aussie-izer 2 | 3 | Websites upside down for those down under! Read more @ https://www.smashingmagazine.com/2021/11/nextjs-wildcard-subdomains/. Written as a short demo of wildcard domains. 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wildcard", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start" 9 | }, 10 | "dependencies": { 11 | "next": "10.0.4", 12 | "react": "17.0.1", 13 | "react-dom": "17.0.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pages/index.js: -------------------------------------------------------------------------------- 1 | import Head from "next/head"; 2 | 3 | export default function App(props) { 4 | switch (props.wildcard) { 5 | case "home": 6 | return ( 7 |
8 | Welcome to the Aussie-izer! This only works for .com domains. If you 9 | want to Aussie-ize{" "} 10 | https://example.com visit{" "} 11 | 12 | https://example.aussieizer.sampoder.com 13 | 14 | .{" "} 15 |
16 | ); 17 | break; 18 | default: 19 | return ( 20 | <> 21 | 36 | 41 | 42 | ); 43 | } 44 | } 45 | 46 | export async function getServerSideProps(context) { 47 | let wildcard = context.req.headers.host.split(".")[0]; 48 | wildcard = 49 | wildcard != "aussieizer" 50 | ? wildcard != "localhost:3000" 51 | ? wildcard 52 | : process.env.TEST_WILDCARD 53 | : "home"; 54 | return { props: { wildcard } }; 55 | } 56 | --------------------------------------------------------------------------------