-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #619 from serlo/patch
refactor: Move all functions to separate files
- Loading branch information
Showing
5 changed files
with
50 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Url } from './utils' | ||
|
||
export async function semanticFileNames(request: Request) { | ||
const url = Url.fromRequest(request) | ||
|
||
if (url.subdomain !== 'assets') return null | ||
|
||
url.host = 'assets.serlo.org' | ||
|
||
const re = /^\/(legacy\/|)((?!legacy)[\w-]+)\/([\w\-+]+)\.(\w+)$/ | ||
const match = re.exec(url.pathname) | ||
|
||
if (!url.pathname.startsWith('/meta') && match) { | ||
const prefix = match[1] | ||
const hash = match[2] | ||
const extension = match[4] | ||
|
||
url.pathname = `${prefix}${hash}.${extension}` | ||
} | ||
return await fetch(url.href, request) | ||
} |
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,9 @@ | ||
import { Url } from './utils' | ||
|
||
export async function enforceHttps(request: Request) { | ||
const url = Url.fromRequest(request) | ||
if (url.subdomain === 'pacts') return null | ||
if (url.protocol !== 'http:') return null | ||
url.protocol = 'https:' | ||
return Promise.resolve(url.toRedirect(301)) | ||
} |
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,16 @@ | ||
import { SentryFactory, Url } from './utils' | ||
|
||
export function sentryHelloWorld( | ||
request: Request, | ||
sentryFactory: SentryFactory, | ||
) { | ||
const url = Url.fromRequest(request) | ||
|
||
if (url.subdomain !== '') return null | ||
if (url.pathname !== '/sentry-report-hello-world') return null | ||
|
||
const sentry = sentryFactory.createReporter('sentry-hello-world') | ||
sentry.captureMessage('Hello World!', 'info') | ||
|
||
return new Response('Hello-World message send to sentry') | ||
} |