rajt 0.0.38 ā 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth/index.ts +1 -1
- package/src/auth/token.ts +1 -1
- package/src/context.ts +12 -0
- package/src/dev.ts +1 -1
- package/src/esbuild.mjs +47 -24
- package/src/register.ts +1 -1
- package/src/request.ts +8 -0
package/package.json
CHANGED
package/src/auth/index.ts
CHANGED
package/src/auth/token.ts
CHANGED
package/src/context.ts
CHANGED
|
@@ -28,4 +28,16 @@ export default class CX {
|
|
|
28
28
|
static get cookie() {
|
|
29
29
|
return this.#cookie
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
static get ip(): string | undefined {
|
|
33
|
+
return this.#c.req.header('cf-connecting-ip')
|
|
34
|
+
|| this.#c.req.header('x-forwarded-for')?.split(',')[0]?.trim()
|
|
35
|
+
|| this.#c.env?.aws?.lambda?.event?.requestContext?.identity?.sourceIp
|
|
36
|
+
|| this.#c.req.header('x-real-ip')
|
|
37
|
+
|| this.#c.env?.remoteAddr?.hostname
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static get userAgent(): string | undefined {
|
|
41
|
+
return this.#c.req.header('user-agent')
|
|
42
|
+
}
|
|
31
43
|
}
|
package/src/dev.ts
CHANGED
|
@@ -25,7 +25,7 @@ const desiredPort = process.env?.PORT ? Number(process.env.PORT) : 3000
|
|
|
25
25
|
getAvailablePort(desiredPort)
|
|
26
26
|
.then(port => {
|
|
27
27
|
if (port != desiredPort)
|
|
28
|
-
console.warn(
|
|
28
|
+
console.warn(`š Port ${desiredPort} was in use, using ${port} as a fallback`)
|
|
29
29
|
|
|
30
30
|
console.log(`š API running on http://localhost:${port}`)
|
|
31
31
|
serve({ fetch, port })
|
package/src/esbuild.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import esbuild from 'esbuild'
|
|
2
|
-
import
|
|
2
|
+
import { dirname, join, relative } from 'path'
|
|
3
3
|
import { fileURLToPath } from 'url'
|
|
4
|
-
import
|
|
4
|
+
import { readFile, stat, writeFile } from 'fs/promises'
|
|
5
5
|
|
|
6
|
-
const __dirname =
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
7
7
|
|
|
8
8
|
const formatSize = (bytes) => {
|
|
9
9
|
if (bytes < 1024) return `${bytes}b`
|
|
@@ -16,10 +16,10 @@ const formatTime = (ms) => {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const buildOptions = {
|
|
19
|
-
entryPoints: [
|
|
19
|
+
entryPoints: [join(__dirname, 'prod.ts')],
|
|
20
20
|
bundle: true,
|
|
21
21
|
minify: true,
|
|
22
|
-
outfile:
|
|
22
|
+
outfile: join(__dirname, '../../../dist/index.js'),
|
|
23
23
|
platform: 'node',
|
|
24
24
|
target: 'node20',
|
|
25
25
|
format: 'esm',
|
|
@@ -27,37 +27,60 @@ const buildOptions = {
|
|
|
27
27
|
legalComments: 'none',
|
|
28
28
|
external: ['@aws-sdk', '@smithy'],
|
|
29
29
|
metafile: true,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
write: false,
|
|
31
|
+
plugins: [
|
|
32
|
+
{
|
|
33
|
+
name: 'preserve-class-names',
|
|
34
|
+
setup(build) {
|
|
35
|
+
build.onLoad(
|
|
36
|
+
{ filter: /(actions|features)\/.*\.ts$/ },
|
|
37
|
+
async (args) => {
|
|
38
|
+
const contents = await readFile(args.path, 'utf8')
|
|
39
|
+
const result = await esbuild.transform(contents, {
|
|
40
|
+
loader: 'ts',
|
|
41
|
+
minify: true,
|
|
42
|
+
keepNames: true
|
|
43
|
+
})
|
|
44
|
+
return { contents: result.code, loader: 'ts' }
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
},
|
|
45
48
|
},
|
|
46
|
-
|
|
49
|
+
{
|
|
50
|
+
name: 'remove-use-strict',
|
|
51
|
+
setup(build) {
|
|
52
|
+
build.onEnd(async (result) => {
|
|
53
|
+
if (!result.outputFiles) return
|
|
54
|
+
|
|
55
|
+
const files = result.outputFiles.filter(file => file.path.endsWith('.js'))
|
|
56
|
+
await Promise.all(files.map(async file => {
|
|
57
|
+
if (!file.path.endsWith('.js')) return
|
|
58
|
+
|
|
59
|
+
await writeFile(
|
|
60
|
+
file.path,
|
|
61
|
+
new TextDecoder()
|
|
62
|
+
.decode(file.contents)
|
|
63
|
+
.replace(/(["'`])\s*use strict\s*\1;?|`use strict`;?/g, '')
|
|
64
|
+
)
|
|
65
|
+
}))
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
]
|
|
47
70
|
}
|
|
48
71
|
|
|
49
72
|
try {
|
|
50
73
|
const startTime = Date.now()
|
|
51
74
|
const result = await esbuild.build(buildOptions)
|
|
52
75
|
|
|
53
|
-
const cwd =
|
|
76
|
+
const cwd = join(__dirname, '../../..')
|
|
54
77
|
|
|
55
78
|
const outputFile = buildOptions.outfile
|
|
56
|
-
const stats = await
|
|
79
|
+
const stats = await stat(outputFile)
|
|
57
80
|
const size = formatSize(stats.size)
|
|
58
81
|
|
|
59
82
|
console.log(`\nā”ļø Done in ${formatTime(Date.now() - startTime)}`)
|
|
60
|
-
console.log(` ${
|
|
83
|
+
console.log(` ${relative(join(cwd, 'node_modules/rajt/src'), buildOptions.entryPoints[0])} ā ${relative(cwd, outputFile)}`)
|
|
61
84
|
console.log(` Size: ${size}`)
|
|
62
85
|
console.log(` Files: ${Object.keys(result.metafile.outputs).length}`)
|
|
63
86
|
} catch (error) {
|
package/src/register.ts
CHANGED
|
@@ -2,7 +2,7 @@ export const handlers: Record<string, Function> = {}
|
|
|
2
2
|
|
|
3
3
|
export function registerHandler(id: string, handler: any) {
|
|
4
4
|
if (id in handlers)
|
|
5
|
-
console.warn(
|
|
5
|
+
console.warn(`š Handler "${id}" has already been registered`)
|
|
6
6
|
|
|
7
7
|
handlers[id] = handler
|
|
8
8
|
}
|