@dcl/http-server 1.0.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/README.md +3 -0
- package/dist/benchmark.d.ts +1 -0
- package/dist/benchmark.js +94 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/cors.d.ts +35 -0
- package/dist/cors.js +138 -0
- package/dist/cors.js.map +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +3 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/injectors.d.ts +5 -0
- package/dist/injectors.js +22 -0
- package/dist/injectors.js.map +1 -0
- package/dist/layer.d.ts +58 -0
- package/dist/layer.js +102 -0
- package/dist/layer.js.map +1 -0
- package/dist/logic.d.ts +12 -0
- package/dist/logic.js +288 -0
- package/dist/logic.js.map +1 -0
- package/dist/methods.d.ts +6 -0
- package/dist/methods.js +16 -0
- package/dist/methods.js.map +1 -0
- package/dist/metrics.d.ts +36 -0
- package/dist/metrics.js +107 -0
- package/dist/metrics.js.map +1 -0
- package/dist/middleware.d.ts +9 -0
- package/dist/middleware.js +35 -0
- package/dist/middleware.js.map +1 -0
- package/dist/router.d.ts +190 -0
- package/dist/router.js +516 -0
- package/dist/router.js.map +1 -0
- package/dist/server-handler.d.ts +1 -0
- package/dist/server-handler.js +34 -0
- package/dist/server-handler.js.map +1 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +176 -0
- package/dist/server.js.map +1 -0
- package/dist/status-checks.d.ts +33 -0
- package/dist/status-checks.js +154 -0
- package/dist/status-checks.js.map +1 -0
- package/dist/terminator.d.ts +18 -0
- package/dist/terminator.js +128 -0
- package/dist/terminator.js.map +1 -0
- package/dist/test-component.d.ts +22 -0
- package/dist/test-component.js +89 -0
- package/dist/test-component.js.map +1 -0
- package/dist/test-server.d.ts +21 -0
- package/dist/test-server.js +81 -0
- package/dist/test-server.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ws.d.ts +8 -0
- package/dist/ws.js +32 -0
- package/dist/ws.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createTestServerComponent = createTestServerComponent;
|
|
37
|
+
const fetch = __importStar(require("node-fetch"));
|
|
38
|
+
const server_handler_1 = require("./server-handler");
|
|
39
|
+
const stream_1 = require("stream");
|
|
40
|
+
/**
|
|
41
|
+
* Creates a http-server component for tests
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
function createTestServerComponent() {
|
|
45
|
+
let currentContext = {};
|
|
46
|
+
const serverHandler = (0, server_handler_1.createServerHandler)();
|
|
47
|
+
const ret = {
|
|
48
|
+
async fetch(url, initRequest) {
|
|
49
|
+
let req;
|
|
50
|
+
if (url instanceof fetch.Request) {
|
|
51
|
+
req = url;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const tempHeaders = new fetch.Headers(initRequest?.headers);
|
|
55
|
+
const hostname = tempHeaders.get('X-Forwarded-Host') || tempHeaders.get('host') || '0.0.0.0';
|
|
56
|
+
const protocol = tempHeaders.get('X-Forwarded-Proto') == 'https' ? 'https' : 'http';
|
|
57
|
+
let newUrl = new URL(protocol + '://' + hostname + url);
|
|
58
|
+
try {
|
|
59
|
+
newUrl = new URL(url, protocol + '://' + hostname);
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
req = new fetch.Request(newUrl.toString(), initRequest);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const res = await serverHandler.processRequest(currentContext, req);
|
|
66
|
+
if (res.body instanceof stream_1.Stream) {
|
|
67
|
+
// since we have no server and actual socket pipes, what we receive here
|
|
68
|
+
// is a readable stream that needs to be decoupled from it's original
|
|
69
|
+
// stream to ensure a consistent behavior with real servers
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
resolve(new fetch.Response((0, stream_1.pipeline)(res.body, new stream_1.PassThrough(), reject), res));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(error);
|
|
78
|
+
return new fetch.Response('DEV-SERVER-ERROR: ' + (error.stack || error.toString()), { status: 500 });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
use: serverHandler.use,
|
|
82
|
+
setContext(ctx) {
|
|
83
|
+
currentContext = Object.create(ctx);
|
|
84
|
+
},
|
|
85
|
+
resetMiddlewares: serverHandler.resetMiddlewares
|
|
86
|
+
};
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=test-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-component.js","sourceRoot":"","sources":["../src/test-component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,8DA8CC;AA1ED,kDAAmC;AACnC,qDAAsD;AACtD,mCAAsD;AAsBtD;;;GAGG;AACH,SAAgB,yBAAyB;IACvC,IAAI,cAAc,GAAY,EAAS,CAAA;IAEvC,MAAM,aAAa,GAAG,IAAA,oCAAmB,GAAW,CAAA;IAEpD,MAAM,GAAG,GAAsC;QAC7C,KAAK,CAAC,KAAK,CAAC,GAAQ,EAAE,WAAiB;YACrC,IAAI,GAAkB,CAAA;YAEtB,IAAI,GAAG,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC;gBACjC,GAAG,GAAG,GAAG,CAAA;YACX,CAAC;iBAAM,CAAC;gBACN,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;gBAC3D,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAA;gBAC5F,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,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AAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACrC,CAAC;QACD,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;KACjD,CAAA;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IConfigComponent, IHttpServerComponent, ILoggerComponent } from '@well-known-components/interfaces';
|
|
2
|
+
import { Router } from '.';
|
|
3
|
+
export type TestServerAppContext<OtherComponents> = {
|
|
4
|
+
components: TestServerComponents<OtherComponents>;
|
|
5
|
+
};
|
|
6
|
+
export type TestServerComponents<OtherComponents> = {
|
|
7
|
+
logs: ILoggerComponent;
|
|
8
|
+
config: IConfigComponent;
|
|
9
|
+
server: IHttpServerComponent<TestServerAppContext<OtherComponents>>;
|
|
10
|
+
router: Router<TestServerAppContext<OtherComponents>>;
|
|
11
|
+
getBaseUrl: () => Promise<string>;
|
|
12
|
+
getUrl: (url: string) => Promise<string>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Wires together the server and router. Also logs every request that is handled in the process.
|
|
16
|
+
*/
|
|
17
|
+
export declare function wireTestServerComponents<T>(context: TestServerAppContext<T>): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a test server and returns all the components and helpers
|
|
20
|
+
*/
|
|
21
|
+
export declare function initTestServerComponents(): Promise<TestServerComponents<any>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wireTestServerComponents = wireTestServerComponents;
|
|
4
|
+
exports.initTestServerComponents = initTestServerComponents;
|
|
5
|
+
const env_config_provider_1 = require("@well-known-components/env-config-provider");
|
|
6
|
+
const logger_1 = require("@well-known-components/logger");
|
|
7
|
+
const test_helpers_1 = require("@well-known-components/test-helpers");
|
|
8
|
+
const node_fetch_1 = require("node-fetch");
|
|
9
|
+
const stream_1 = require("stream");
|
|
10
|
+
const _1 = require(".");
|
|
11
|
+
/**
|
|
12
|
+
* Wires together the server and router. Also logs every request that is handled in the process.
|
|
13
|
+
*/
|
|
14
|
+
async function wireTestServerComponents(context) {
|
|
15
|
+
const { components } = context;
|
|
16
|
+
components.server.setContext(context);
|
|
17
|
+
components.server.use(async function logger(ctx, next) {
|
|
18
|
+
const resetFG = '\u001b[0m';
|
|
19
|
+
const greenFG = '\u001b[32m';
|
|
20
|
+
const greyFG = '\u001b[30;0m';
|
|
21
|
+
const whiteFG = '\u001b[37m';
|
|
22
|
+
process.stderr.write('req ❭ ' + greenFG + ctx.request.method + ' ' + greyFG + ctx.url.toString() + resetFG + '\n');
|
|
23
|
+
for (let [header, value] of ctx.request.headers) {
|
|
24
|
+
process.stderr.write(' ' + whiteFG + header + ': ' + greyFG + value + '\n');
|
|
25
|
+
}
|
|
26
|
+
const response = await next();
|
|
27
|
+
process.stderr.write('res ❬ ' + greenFG + 'HTTP ' + whiteFG + (response.status || 200) + '\n');
|
|
28
|
+
if (response.headers) {
|
|
29
|
+
for (let [header, value] of new node_fetch_1.Headers(response.headers)) {
|
|
30
|
+
process.stderr.write(' ' + whiteFG + header + ': ' + greyFG + value + '\n');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (response.body) {
|
|
34
|
+
if (Buffer.isBuffer(response.body)) {
|
|
35
|
+
process.stderr.write(response.body.toString() + '\n');
|
|
36
|
+
}
|
|
37
|
+
else if (response.body instanceof stream_1.Readable) {
|
|
38
|
+
process.stderr.write(' ' + '<< STREAM >>\n');
|
|
39
|
+
}
|
|
40
|
+
else if (typeof response.body == 'string') {
|
|
41
|
+
process.stderr.write(' ' + response.body + '\n');
|
|
42
|
+
}
|
|
43
|
+
else if (response.body instanceof ArrayBuffer) {
|
|
44
|
+
process.stderr.write(' ' + '<< ArrayBuffer >>\n');
|
|
45
|
+
}
|
|
46
|
+
else if (typeof response.body == 'object') {
|
|
47
|
+
process.stderr.write(' ' + JSON.stringify(response.body) + '\n');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
process.stderr.write(' ' + '<<BODY ' + Object.prototype.toString.apply(response.body) + '>>\n');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
process.stderr.write('\n');
|
|
54
|
+
return response;
|
|
55
|
+
});
|
|
56
|
+
components.server.use(components.router.middleware());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a test server and returns all the components and helpers
|
|
60
|
+
*/
|
|
61
|
+
async function initTestServerComponents() {
|
|
62
|
+
const config = (0, env_config_provider_1.createConfigComponent)({ ...(0, test_helpers_1.defaultServerConfig)(), LOG_LEVEL: 'INFO' });
|
|
63
|
+
const logs = await (0, logger_1.createLogComponent)({ config });
|
|
64
|
+
const server = await (0, _1.createServerComponent)({ logs, config }, {});
|
|
65
|
+
const router = new _1.Router();
|
|
66
|
+
const getBaseUrl = async () => {
|
|
67
|
+
return `http://${await config.requireString('HTTP_SERVER_HOST')}:${await config.requireString('HTTP_SERVER_PORT')}`;
|
|
68
|
+
};
|
|
69
|
+
const getUrl = async (url) => {
|
|
70
|
+
return (await getBaseUrl()) + url;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
logs,
|
|
74
|
+
config,
|
|
75
|
+
getBaseUrl,
|
|
76
|
+
getUrl,
|
|
77
|
+
router,
|
|
78
|
+
server
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=test-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-server.js","sourceRoot":"","sources":["../src/test-server.ts"],"names":[],"mappings":";;AAwBA,4DA4CC;AAKD,4DAyBC;AAlGD,oFAAkF;AAElF,0DAAkE;AAClE,sEAAyE;AACzE,2CAAoC;AACpC,mCAAiC;AACjC,wBAAiD;AAejD;;GAEG;AACI,KAAK,UAAU,wBAAwB,CAAI,OAAgC;IAChF,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAA;IAE9B,UAAU,CAAC,MAAM,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UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAA;AACvD,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,wBAAwB;IAC5C,MAAM,MAAM,GAAG,IAAA,2CAAqB,EAAC,EAAE,GAAG,IAAA,kCAAmB,GAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAA;IAErF,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAkB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEjD,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAqB,EAA4B,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;IAE3F,MAAM,MAAM,GAAG,IAAI,SAAM,EAA6B,CAAA;IAEtD,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,OAAO,UAAU,MAAM,MAAM,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,MAAM,MAAM,CAAC,aAAa,CAAC,kBAAkB,CAAC,EAAE,CAAA;IACrH,CAAC,CAAA;IAED,MAAM,MAAM,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;QACnC,OAAO,CAAC,MAAM,UAAU,EAAE,CAAC,GAAG,GAAG,CAAA;IACnC,CAAC,CAAA;IAED,OAAO;QACL,IAAI;QACJ,MAAM;QACN,UAAU;QACV,MAAM;QACN,MAAM;QACN,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IConfigComponent, ILoggerComponent } from '@well-known-components/interfaces';
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type * as https from 'https';
|
|
4
|
+
import type { Socket } from 'net';
|
|
5
|
+
import { CorsOptions } from './cors';
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
* @deprecated Not the final release
|
|
9
|
+
*/
|
|
10
|
+
export interface WebSocketServer {
|
|
11
|
+
handleUpgrade(request: http.IncomingMessage, socket: Socket, upgradeHead: Buffer, callback: (client: any, request: http.IncomingMessage) => void): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type ServerComponents = {
|
|
17
|
+
config: IConfigComponent;
|
|
18
|
+
logs: ILoggerComponent;
|
|
19
|
+
ws?: WebSocketServer;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export type IHttpServerOptions = {
|
|
25
|
+
cors?: CorsOptions;
|
|
26
|
+
keepAliveTimeout?: number;
|
|
27
|
+
headersTimeout?: number;
|
|
28
|
+
} & ({
|
|
29
|
+
https: https.ServerOptions;
|
|
30
|
+
} | {
|
|
31
|
+
http: http.ServerOptions;
|
|
32
|
+
});
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/ws.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IHttpServerComponent } from '@well-known-components/interfaces';
|
|
2
|
+
import type { WebSocket as WS } from 'ws';
|
|
3
|
+
export type WebSocketCallback = (ws: WS) => Promise<void> | void;
|
|
4
|
+
/**
|
|
5
|
+
* @alpha
|
|
6
|
+
* @deprecated Not stable
|
|
7
|
+
*/
|
|
8
|
+
export declare function upgradeWebSocketResponse(cb: WebSocketCallback): IHttpServerComponent.IResponse;
|
package/dist/ws.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upgradeWebSocketResponse = upgradeWebSocketResponse;
|
|
4
|
+
exports.withWebSocketCallback = withWebSocketCallback;
|
|
5
|
+
exports.getWebSocketCallback = getWebSocketCallback;
|
|
6
|
+
const wsSymbol = Symbol('WebSocketResponse');
|
|
7
|
+
/**
|
|
8
|
+
* @alpha
|
|
9
|
+
* @deprecated Not stable
|
|
10
|
+
*/
|
|
11
|
+
function upgradeWebSocketResponse(cb) {
|
|
12
|
+
return withWebSocketCallback({
|
|
13
|
+
status: 101
|
|
14
|
+
}, cb);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
* @deprecated Not stable
|
|
19
|
+
*/
|
|
20
|
+
function withWebSocketCallback(obj, cb) {
|
|
21
|
+
;
|
|
22
|
+
obj[wsSymbol] = cb;
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
* @deprecated Not stable
|
|
28
|
+
*/
|
|
29
|
+
function getWebSocketCallback(obj) {
|
|
30
|
+
return obj[wsSymbol] || null;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ws.js.map
|
package/dist/ws.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":";;AAWA,4DAOC;AAMD,sDAGC;AAMD,oDAEC;AAhCD,MAAM,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAI5C;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,EAAqB;IAC5D,OAAO,qBAAqB,CAC1B;QACE,MAAM,EAAE,GAAG;KACZ,EACD,EAAE,CACH,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAmB,GAAM,EAAE,EAAqB;IACnF,CAAC;IAAC,GAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;IAC5B,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAmB,GAAM;IAC3D,OAAQ,GAAW,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA;AACvC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcl/http-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "http server component",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@types/http-errors": "^2.0.4",
|
|
12
|
+
"destroy": "^1.2.0",
|
|
13
|
+
"fp-future": "^1.0.1",
|
|
14
|
+
"http-errors": "^2.0.0",
|
|
15
|
+
"mitt": "^3.0.0",
|
|
16
|
+
"node-fetch": "^2.6.9",
|
|
17
|
+
"on-finished": "^2.4.1",
|
|
18
|
+
"path-to-regexp": "^6.3.0",
|
|
19
|
+
"reflect-metadata": "^0.2.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/busboy": "^1.5.4",
|
|
23
|
+
"@types/destroy": "^1.0.0",
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
|
+
"@types/node": "^20.3.2",
|
|
26
|
+
"@types/node-fetch": "^2.6.12",
|
|
27
|
+
"@types/on-finished": "^2.3.4",
|
|
28
|
+
"@types/ws": "^8.5.4",
|
|
29
|
+
"@well-known-components/env-config-provider": "^1.1.1",
|
|
30
|
+
"@well-known-components/interfaces": "^1.5.1",
|
|
31
|
+
"@well-known-components/logger": "^3.1.2",
|
|
32
|
+
"@well-known-components/test-helpers": "^1.3.0",
|
|
33
|
+
"@jest/test-sequencer": "^30.0.2",
|
|
34
|
+
"busboy": "^1.6.0",
|
|
35
|
+
"form-data": "^4.0.0",
|
|
36
|
+
"jest": "^30.0.2",
|
|
37
|
+
"ts-jest": "^29.4.0",
|
|
38
|
+
"typescript": "^5.8.2",
|
|
39
|
+
"undici": "^7.4.0",
|
|
40
|
+
"ws": "^8.12.1"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"dev": "tsc --watch",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"test": "jest",
|
|
47
|
+
"lint": "echo \"No linting configured\""
|
|
48
|
+
}
|
|
49
|
+
}
|