-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π§βπ» DevOps - Add Intermediary Staging Slot (#1702)
* Added swap command + intermediate staging environment * Added Node LTS to Docker container * Added correct tag for Docker deployment * Added staging deployment to Bicep * Removed deletion of staging slot * Added new env variable to distinguish between PR and production builds * Removed writefile * Changed to LTS Alphine instead of 20.9 * un-renamed app service bicep * Removed APP_ENV, replaced with decorator for middleware * Removed erraneously added redirects * noIndex - handle condition where url does not have www prefix * noIndex - linting fixes * Refactor noIndex middleware to improve readability --------- Co-authored-by: Matt Wicks [SSW] <[email protected]> Co-authored-by: Matt Wicks <[email protected]>
- Loading branch information
1 parent
a21f126
commit ed389a6
Showing
10 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { addNoIndexHeaders } from "./middleware/noIndex"; | ||
|
||
export function middleware(request: NextRequest) { | ||
const response = NextResponse.next(); | ||
|
||
addNoIndexHeaders(request, response); | ||
|
||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const addNoIndexHeaders = ( | ||
request: NextRequest, | ||
response: NextResponse | ||
) => { | ||
try { | ||
const siteUrl = new URL(process.env.SITE_URL || "https://www.ssw.com.au"); | ||
|
||
if ( | ||
sanitizeHostname(request.nextUrl.hostname) !== | ||
sanitizeHostname(siteUrl.hostname) | ||
) { | ||
response.headers.set("X-Robots-Tag", "noindex"); | ||
} | ||
} catch (err) { | ||
// If TypeError is thrown from an invalid URL, fail gracefully | ||
if (err instanceof TypeError) { | ||
return; | ||
} | ||
|
||
throw err; | ||
} | ||
}; | ||
|
||
const sanitizeHostname = (hostname: string) => { | ||
if (hostname.startsWith("www.")) { | ||
return hostname.substring(4); | ||
} | ||
|
||
return hostname; | ||
}; |