generated from egoist/ts-lib-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EGOIST
committed
May 5, 2022
1 parent
34cbb19
commit a91f477
Showing
16 changed files
with
326 additions
and
81 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
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 @@ | ||
export * from "./dist/polyfills" |
6 changes: 5 additions & 1 deletion
6
packages/vite-vercel/src/server-prepare.ts → packages/vercel-utils/src/polyfills.ts
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 |
---|---|---|
@@ -1,51 +1,4 @@ | ||
import { validateURL } from "./server-utils" | ||
|
||
const REDIRECTS = new Set([301, 302, 303, 307, 308]) | ||
|
||
export class MiddlewareRequest extends Request { | ||
/** Only available on Vercel */ | ||
geo?: { | ||
city?: string | ||
country?: string | ||
region?: string | ||
latitude?: string | ||
longitude?: string | ||
} | ||
|
||
/** Only available on Vercel */ | ||
ip?: string | ||
} | ||
|
||
export class MiddlewareResponse extends Response { | ||
static rewrite(destination: string | URL) { | ||
return new MiddlewareResponse(null, { | ||
headers: { | ||
"x-middleware-rewrite": validateURL(destination), | ||
}, | ||
}) | ||
} | ||
|
||
static next() { | ||
return new MiddlewareResponse(null, { | ||
headers: { | ||
"x-middleware-next": "1", | ||
}, | ||
}) | ||
} | ||
|
||
static redirect(url: string | URL, status = 307) { | ||
if (!REDIRECTS.has(status)) { | ||
throw new RangeError( | ||
'Failed to execute "redirect" on "response": Invalid status code', | ||
) | ||
} | ||
|
||
const destination = validateURL(url) | ||
return new MiddlewareResponse(destination, { | ||
headers: { Location: destination }, | ||
status, | ||
}) | ||
} | ||
} | ||
|
||
export { MiddlewareRequest } from "./spec-extensions/request" | ||
export { MiddlewareResponse } from "./spec-extensions/response" | ||
export { MiddlewareFetchEvent } from "./spec-extensions/fetch-event" | ||
export { isBot } from "./server-utils" |
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,3 @@ | ||
import { FetchEvent } from "next/dist/server/web/spec-compliant/fetch-event" | ||
|
||
export class MiddlewareFetchEvent extends FetchEvent {} |
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,15 @@ | ||
import { Request } from "next/dist/server/web/spec-compliant/request" | ||
|
||
export class MiddlewareRequest extends Request { | ||
/** Only available on Vercel */ | ||
geo?: { | ||
city?: string | ||
country?: string | ||
region?: string | ||
latitude?: string | ||
longitude?: string | ||
} | ||
|
||
/** Only available on Vercel */ | ||
ip?: string | ||
} |
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,3 @@ | ||
import { NextResponse } from "next/dist/server/web/spec-extension/response" | ||
|
||
export class MiddlewareResponse extends NextResponse {} |
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 @@ | ||
import "vercel-utils/polyfills" |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from "vercel-utils/server" | ||
export { | ||
MiddlewareFetchEvent, | ||
MiddlewareRequest, | ||
MiddlewareResponse, | ||
} from "vercel-utils/server" |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { defineConfig } from "tsup" | ||
|
||
export default defineConfig({ | ||
target: "node14", | ||
entry: ["./src/index.ts", "./src/server.ts", "./src/server-prepare.ts"], | ||
format: ["esm", "cjs"], | ||
dts: true, | ||
splitting: true, | ||
shims: false, | ||
export default defineConfig(() => { | ||
return { | ||
target: "node14", | ||
entry: ["./src/index.ts", "./src/server.ts", "./src/polyfills.ts"], | ||
format: ["cjs", "esm"], | ||
dts: true, | ||
splitting: true, | ||
shims: false, | ||
minify: true, | ||
sourcemap: true, | ||
} | ||
}) |
Oops, something went wrong.