@devvit/server 0.11.17-next-2025-06-04-b6703d5a9.0 → 0.11.17-next-2025-06-04-202f3d3bb.0
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/create-server.d.ts +2 -6
- package/create-server.d.ts.map +1 -1
- package/create-server.js +1 -8
- package/index.d.ts +0 -1
- package/index.d.ts.map +1 -1
- package/index.js +0 -1
- package/package.json +7 -9
- package/webbit-server.d.ts +4 -0
- package/webbit-server.d.ts.map +1 -0
- package/webbit-server.js +30 -0
- package/source-maps/source-maps.d.ts +0 -15
- package/source-maps/source-maps.d.ts.map +0 -1
- package/source-maps/source-maps.js +0 -72
- package/source-maps/source-maps.test.d.ts.map +0 -1
package/create-server.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createServer as nodeCreateServer } from 'node:http';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new Devvit server. This implements the same API as Node.js's `createServer` function,
|
|
4
4
|
* but we do not guarantee that this actually creates an HTTP server of any kind - it may be any
|
|
5
5
|
* kind of server under the hood. However, it will behave like an HTTP server in terms of the API.
|
|
6
6
|
*/
|
|
7
|
-
export declare const createServer:
|
|
8
|
-
req: InstanceType<Request>;
|
|
9
|
-
}) => any), requestListener?: (req: InstanceType<Request>, res: InstanceType<Response> & {
|
|
10
|
-
req: InstanceType<Request>;
|
|
11
|
-
}) => any) => Server<Request, Response>;
|
|
7
|
+
export declare const createServer: typeof nodeCreateServer;
|
|
12
8
|
declare global {
|
|
13
9
|
namespace globalThis {
|
|
14
10
|
var enableWebbitBundlingHack: boolean;
|
package/create-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAI7D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,OAAO,gBAYjC,CAAC;AAuCF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU,CAAC;QAEnB,IAAI,wBAAwB,EAAE,OAAO,CAAC;KACvC;CACF"}
|
package/create-server.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
import { createServer as nodeCreateServer } from 'node:http';
|
|
3
2
|
import { runWithContext } from './context.js';
|
|
4
3
|
import { RequestContext } from './request-context.js';
|
|
5
|
-
import { runWithSourceMap } from './source-maps/source-maps.js';
|
|
6
|
-
// This constant represents the bundle ID to match code to its source map
|
|
7
|
-
// and needs to match the one the source map was initiated with from WebbitLoader.
|
|
8
|
-
const WEBBIT_BUNDLE_ID = 'webbit-server';
|
|
9
4
|
/**
|
|
10
5
|
* Creates a new Devvit server. This implements the same API as Node.js's `createServer` function,
|
|
11
6
|
* but we do not guarantee that this actually creates an HTTP server of any kind - it may be any
|
|
@@ -21,9 +16,7 @@ function _createServer(options, requestListener) {
|
|
|
21
16
|
const server = nodeCreateServer(options, async (req, res) => {
|
|
22
17
|
const context = RequestContext(req.headers);
|
|
23
18
|
return runWithContext(context, async () => {
|
|
24
|
-
return
|
|
25
|
-
return requestListener?.(req, res);
|
|
26
|
-
});
|
|
19
|
+
return requestListener?.(req, res);
|
|
27
20
|
});
|
|
28
21
|
});
|
|
29
22
|
// Modify the listen callback slightly, to do the Devvit-y bundling hack
|
package/index.d.ts
CHANGED
|
@@ -3,5 +3,4 @@ export { createServer } from './create-server.js';
|
|
|
3
3
|
export { defineConfig } from './define-config.js';
|
|
4
4
|
export { getServerPort } from './get-server-port.js';
|
|
5
5
|
export { RequestContext, setRequestContext } from './request-context.js';
|
|
6
|
-
export { initializeSourceMap, runWithSourceMap } from './source-maps/source-maps.js';
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/index.js
CHANGED
|
@@ -3,4 +3,3 @@ export { createServer } from './create-server.js';
|
|
|
3
3
|
export { defineConfig } from './define-config.js';
|
|
4
4
|
export { getServerPort } from './get-server-port.js';
|
|
5
5
|
export { RequestContext, setRequestContext } from './request-context.js';
|
|
6
|
-
export { initializeSourceMap, runWithSourceMap } from './source-maps/source-maps.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/server",
|
|
3
|
-
"version": "0.11.17-next-2025-06-04-
|
|
3
|
+
"version": "0.11.17-next-2025-06-04-202f3d3bb.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,15 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"types": "./index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@devvit/protos": "0.11.17-next-2025-06-04-
|
|
27
|
-
"@devvit/public-api": "0.11.17-next-2025-06-04-
|
|
28
|
-
"@devvit/shared-types": "0.11.17-next-2025-06-04-
|
|
29
|
-
"@gunsch/source-map": "0.7.6"
|
|
26
|
+
"@devvit/protos": "0.11.17-next-2025-06-04-202f3d3bb.0",
|
|
27
|
+
"@devvit/public-api": "0.11.17-next-2025-06-04-202f3d3bb.0",
|
|
28
|
+
"@devvit/shared-types": "0.11.17-next-2025-06-04-202f3d3bb.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"@devvit/repo-tools": "0.11.17-next-2025-06-04-
|
|
33
|
-
"@devvit/tsconfig": "0.11.17-next-2025-06-04-
|
|
34
|
-
"esbuild": "0.23.0",
|
|
31
|
+
"@devvit/repo-tools": "0.11.17-next-2025-06-04-202f3d3bb.0",
|
|
32
|
+
"@devvit/tsconfig": "0.11.17-next-2025-06-04-202f3d3bb.0",
|
|
35
33
|
"eslint": "9.11.1",
|
|
36
34
|
"typescript": "5.8.3",
|
|
37
35
|
"vitest": "1.6.1"
|
|
@@ -40,5 +38,5 @@
|
|
|
40
38
|
"directory": "dist"
|
|
41
39
|
},
|
|
42
40
|
"source": "./src/index.ts",
|
|
43
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "328a86e66bfecc7b0d3eadba8b48e20d8fcabf02"
|
|
44
42
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webbit-server.d.ts","sourceRoot":"","sources":["../src/webbit-server.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,oDAAoD,CAAC;AAM5D,wBAAgB,YAAY,IAAI,IAAI,CAInC;AAED,wBAAgB,eAAe,IAAI,YAAY,CAsB9C"}
|
package/webbit-server.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HttpMethod, WebbitServerDefinition, } from '@devvit/protos/types/devvit/actor/webbit/webbit.js';
|
|
2
|
+
import { Devvit } from '@devvit/public-api';
|
|
3
|
+
import { extendDevvitPrototype } from '@devvit/public-api/devvit/internals/helpers/extendDevvitPrototype.js';
|
|
4
|
+
import { getServerPort } from './get-server-port.js';
|
|
5
|
+
export function webbitEnable() {
|
|
6
|
+
const server = newWebbitServer();
|
|
7
|
+
extendDevvitPrototype('Request', server.Request);
|
|
8
|
+
Devvit.provide(WebbitServerDefinition);
|
|
9
|
+
}
|
|
10
|
+
export function newWebbitServer() {
|
|
11
|
+
return {
|
|
12
|
+
async Request(req, meta) {
|
|
13
|
+
const port = getServerPort();
|
|
14
|
+
// only set the body if the method is not GET or HEAD
|
|
15
|
+
const body = [HttpMethod.GET, HttpMethod.HEAD].includes(req.method) ? null : req.body;
|
|
16
|
+
const rsp = await fetch(new URL(req.path, `http://webbit.local:${port}`), {
|
|
17
|
+
body,
|
|
18
|
+
headers: [
|
|
19
|
+
...Object.entries(req.headers),
|
|
20
|
+
// devvit- headers alway have priority.
|
|
21
|
+
...Object.entries(meta ?? {}).map(([k, v]) => [k, v.values.join()]),
|
|
22
|
+
],
|
|
23
|
+
method: HttpMethod[req.method],
|
|
24
|
+
});
|
|
25
|
+
const headers = {};
|
|
26
|
+
rsp.headers.forEach((v, k) => (headers[k] = v));
|
|
27
|
+
return { body: new Uint8Array(await rsp.arrayBuffer()), headers, statusCode: rsp.status };
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Initializes source map for exception handling within this process. Multiple source maps
|
|
3
|
-
* may be reigstered with unique bundle IDs.
|
|
4
|
-
* If no source map is provided, this method exits early.
|
|
5
|
-
* @param codeBundleId Identifier for the code bundle, should be 1:1 with unique source maps within this process.
|
|
6
|
-
* @param sourceMap Source map for this code bundle, undefined if no source map is available.
|
|
7
|
-
*/
|
|
8
|
-
export declare function initializeSourceMap(codeBundleId: string, sourceMap: string | undefined): void;
|
|
9
|
-
/**
|
|
10
|
-
* Executes code with exception handling that will be unwound using the provided source map.
|
|
11
|
-
* @param codeBundleId Identifier for the code bundle, should be 1:1 with unique source maps.
|
|
12
|
-
* @param callback Function to execute that may throw an error
|
|
13
|
-
*/
|
|
14
|
-
export declare function runWithSourceMap<T>(codeBundleId: string, callback: () => T): Promise<T>;
|
|
15
|
-
//# sourceMappingURL=source-maps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-maps.d.ts","sourceRoot":"","sources":["../../src/source-maps/source-maps.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAO7F;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAY7F"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { SourceMapConsumer } from '@gunsch/source-map';
|
|
3
|
-
const currentCodeBundle = new AsyncLocalStorage();
|
|
4
|
-
const sourceMapRegistry = new Map();
|
|
5
|
-
/**
|
|
6
|
-
* Initializes source map for exception handling within this process. Multiple source maps
|
|
7
|
-
* may be reigstered with unique bundle IDs.
|
|
8
|
-
* If no source map is provided, this method exits early.
|
|
9
|
-
* @param codeBundleId Identifier for the code bundle, should be 1:1 with unique source maps within this process.
|
|
10
|
-
* @param sourceMap Source map for this code bundle, undefined if no source map is available.
|
|
11
|
-
*/
|
|
12
|
-
export function initializeSourceMap(codeBundleId, sourceMap) {
|
|
13
|
-
if (sourceMapRegistry.has(codeBundleId)) {
|
|
14
|
-
throw new Error(`Source map for code bundle ID "${codeBundleId}" is already registered. Please use a unique ID for each source map.`);
|
|
15
|
-
}
|
|
16
|
-
sourceMapRegistry.set(codeBundleId, sourceMap || '');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Executes code with exception handling that will be unwound using the provided source map.
|
|
20
|
-
* @param codeBundleId Identifier for the code bundle, should be 1:1 with unique source maps.
|
|
21
|
-
* @param callback Function to execute that may throw an error
|
|
22
|
-
*/
|
|
23
|
-
export async function runWithSourceMap(codeBundleId, callback) {
|
|
24
|
-
return currentCodeBundle.run(codeBundleId, async () => {
|
|
25
|
-
try {
|
|
26
|
-
return await callback();
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
// Ensure we dump this to the logs, since it's not always logged by default.
|
|
30
|
-
if (error instanceof Error && error.stack) {
|
|
31
|
-
console.error(error);
|
|
32
|
-
}
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// Override Node's stack trace formatter to guarantee we can unwind stack traces
|
|
38
|
-
// created in any context.
|
|
39
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
40
|
-
Error.prepareStackTrace = function (error, stackTraces) {
|
|
41
|
-
try {
|
|
42
|
-
// Use the original stack trace formatter if we don't have a source map or don't know what
|
|
43
|
-
// code bundle we're currently operating in
|
|
44
|
-
const currentCodeBundleId = currentCodeBundle.getStore();
|
|
45
|
-
const sourceMap = currentCodeBundleId && sourceMapRegistry.get(currentCodeBundleId);
|
|
46
|
-
if (!sourceMap) {
|
|
47
|
-
return originalPrepareStackTrace ? originalPrepareStackTrace(error, stackTraces) : undefined;
|
|
48
|
-
}
|
|
49
|
-
const sourceMapConsumer = new SourceMapConsumer(sourceMap);
|
|
50
|
-
const mappedStack = stackTraces.map((site) => {
|
|
51
|
-
const fileName = site.getFileName() || '';
|
|
52
|
-
const lineNumber = site.getLineNumber() || 0;
|
|
53
|
-
const columnNumber = site.getColumnNumber() || 0;
|
|
54
|
-
if (!lineNumber) {
|
|
55
|
-
return ` at ${site.getFunctionName() || '<anonymous>'} (${fileName || '??'}:??:${columnNumber || '??'})`;
|
|
56
|
-
}
|
|
57
|
-
const originalPos = sourceMapConsumer.originalPositionFor({
|
|
58
|
-
line: lineNumber,
|
|
59
|
-
column: columnNumber,
|
|
60
|
-
});
|
|
61
|
-
if (originalPos.source) {
|
|
62
|
-
return ` at ${site.getFunctionName() || '<anonymous>'} (${originalPos.source}:${originalPos.line}:${originalPos.column})`;
|
|
63
|
-
}
|
|
64
|
-
return ` at ${site.getFunctionName() || '<anonymous>'} (${fileName}:${lineNumber}:${columnNumber})`;
|
|
65
|
-
});
|
|
66
|
-
return `${error.name}: ${error.message}\n${mappedStack.join('\n')}`;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
// If there are any issues, fall back to the original stack trace formatter
|
|
70
|
-
return originalPrepareStackTrace ? originalPrepareStackTrace(error, stackTraces) : undefined;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-maps.test.d.ts","sourceRoot":"","sources":["../../src/source-maps/source-maps.test.ts"],"names":[],"mappings":""}
|