@arkstack/driver-express 0.3.7 → 0.3.8
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/dist/index.d.ts +2 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ArkstackKitDriver, ArkstackMiddlewareConfig, PromiseOrValue } from "@ar
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
interface ExpressDriverOptions {
|
|
6
6
|
bindRouter: (app: Express) => PromiseOrValue<void>;
|
|
7
|
+
mountPublicAssets?: (app: Express, publicPath: string) => PromiseOrValue<void>;
|
|
7
8
|
errorHandler?: ErrorRequestHandler | Handler;
|
|
8
9
|
}
|
|
9
10
|
declare class ExpressDriver extends ArkstackKitDriver<Express, Handler> {
|
|
@@ -11,7 +12,7 @@ declare class ExpressDriver extends ArkstackKitDriver<Express, Handler> {
|
|
|
11
12
|
private readonly options;
|
|
12
13
|
constructor(options: ExpressDriverOptions);
|
|
13
14
|
createApp(): Express;
|
|
14
|
-
mountPublicAssets(app: Express, publicPath: string): void
|
|
15
|
+
mountPublicAssets(app: Express, publicPath: string): PromiseOrValue<void>;
|
|
15
16
|
bindRouter(app: Express): PromiseOrValue<void>;
|
|
16
17
|
applyMiddleware(app: Express, middleware: Handler | ArkstackMiddlewareConfig<Handler>): void;
|
|
17
18
|
registerErrorHandler(app: Express): void;
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,16 @@ var ExpressDriver = class extends ArkstackKitDriver {
|
|
|
34
34
|
* @param publicPath
|
|
35
35
|
*/
|
|
36
36
|
mountPublicAssets(app, publicPath) {
|
|
37
|
-
|
|
37
|
+
if (this.options.mountPublicAssets) return this.options.mountPublicAssets(app, publicPath);
|
|
38
|
+
app.use(express.static(publicPath, {
|
|
39
|
+
maxAge: "1y",
|
|
40
|
+
immutable: true,
|
|
41
|
+
setHeaders: (res) => {
|
|
42
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
43
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS");
|
|
44
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
38
47
|
}
|
|
39
48
|
/**
|
|
40
49
|
* Binds the router to the Express application using the provided bindRouter function.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import express, { type ErrorRequestHandler, type Express, type Handler } from 'express'\n\nimport { ArkstackKitDriver, ArkstackMiddlewareConfig, PromiseOrValue } from '@arkstack/contract'\nimport { Logger } from '@arkstack/common'\n\nexport interface ExpressDriverOptions {\n bindRouter: (app: Express) => PromiseOrValue<void>;\n errorHandler?: ErrorRequestHandler | Handler;\n}\n\n/**\n * The ExpressDriver class implements the ArkstackKitDriver \n * contract for the Express framework.\n */\nexport class ExpressDriver extends ArkstackKitDriver<Express, Handler> {\n readonly name = 'express'\n private readonly options: ExpressDriverOptions\n\n /**\n * Creates an instance of ExpressDriver.\n * \n * @param options \n */\n constructor(options: ExpressDriverOptions) {\n super()\n this.options = options\n }\n\n /**\n * Creates an Express application instance.\n * \n * @returns \n */\n createApp (): Express {\n return express()\n }\n\n /**\n * Mounts static assets from the specified public path to the Express application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: Express, publicPath: string): void {\n app.use(express.static(publicPath))\n }\n\n /**\n * Binds the router to the Express application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: Express): PromiseOrValue<void> {\n return this.options.bindRouter(app)\n }\n\n /**\n * Applies middleware to the Express application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (\n app: Express,\n middleware: Handler | ArkstackMiddlewareConfig<Handler>,\n ): void {\n if (typeof middleware === 'function') {\n app.use(middleware)\n\n return\n }\n\n for (const [pos, entries] of Object.entries(middleware) as [string, Handler[]][]) {\n for (const entry of entries) {\n if (pos === 'after') {\n app.use(async (req, res, next) => {\n res.once('finish', async () => {\n await entry(req, res, next)\n })\n next()\n })\n } else {\n app.use(entry)\n }\n }\n }\n }\n\n /**\n * Registers an error handler middleware to the Express \n * application if provided in the options.\n * \n * @param app \n */\n registerErrorHandler (app: Express): void {\n if (this.options.errorHandler) {\n app.use(this.options.errorHandler as ErrorRequestHandler)\n }\n }\n\n /**\n * Starts the Express server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: Express, port: number): void {\n app.listen(port, () => {\n Logger.log([\n ['Server is running on', 'white'],\n [`http://localhost:${port}`, 'cyan']\n ], ' ')\n })\n }\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import express, { type ErrorRequestHandler, type Express, type Handler } from 'express'\n\nimport { ArkstackKitDriver, ArkstackMiddlewareConfig, PromiseOrValue } from '@arkstack/contract'\nimport { Logger } from '@arkstack/common'\n\nexport interface ExpressDriverOptions {\n bindRouter: (app: Express) => PromiseOrValue<void>;\n mountPublicAssets?: (app: Express, publicPath: string) => PromiseOrValue<void>;\n errorHandler?: ErrorRequestHandler | Handler;\n}\n\n/**\n * The ExpressDriver class implements the ArkstackKitDriver \n * contract for the Express framework.\n */\nexport class ExpressDriver extends ArkstackKitDriver<Express, Handler> {\n readonly name = 'express'\n private readonly options: ExpressDriverOptions\n\n /**\n * Creates an instance of ExpressDriver.\n * \n * @param options \n */\n constructor(options: ExpressDriverOptions) {\n super()\n this.options = options\n }\n\n /**\n * Creates an Express application instance.\n * \n * @returns \n */\n createApp (): Express {\n return express()\n }\n\n /**\n * Mounts static assets from the specified public path to the Express application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: Express, publicPath: string): PromiseOrValue<void> {\n if (this.options.mountPublicAssets) {\n return this.options.mountPublicAssets(app, publicPath)\n }\n\n app.use(express.static(publicPath, {\n maxAge: '1y',\n immutable: true,\n setHeaders: (res) => {\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS')\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')\n },\n }))\n }\n\n /**\n * Binds the router to the Express application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: Express): PromiseOrValue<void> {\n return this.options.bindRouter(app)\n }\n\n /**\n * Applies middleware to the Express application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (\n app: Express,\n middleware: Handler | ArkstackMiddlewareConfig<Handler>,\n ): void {\n if (typeof middleware === 'function') {\n app.use(middleware)\n\n return\n }\n\n for (const [pos, entries] of Object.entries(middleware) as [string, Handler[]][]) {\n for (const entry of entries) {\n if (pos === 'after') {\n app.use(async (req, res, next) => {\n res.once('finish', async () => {\n await entry(req, res, next)\n })\n next()\n })\n } else {\n app.use(entry)\n }\n }\n }\n }\n\n /**\n * Registers an error handler middleware to the Express \n * application if provided in the options.\n * \n * @param app \n */\n registerErrorHandler (app: Express): void {\n if (this.options.errorHandler) {\n app.use(this.options.errorHandler as ErrorRequestHandler)\n }\n }\n\n /**\n * Starts the Express server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: Express, port: number): void {\n app.listen(port, () => {\n Logger.log([\n ['Server is running on', 'white'],\n [`http://localhost:${port}`, 'cyan']\n ], ' ')\n })\n }\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,gBAAb,cAAmC,kBAAoC;CACnE,AAAS,OAAO;CAChB,AAAiB;;;;;;CAOjB,YAAY,SAA+B;AACvC,SAAO;AACP,OAAK,UAAU;;;;;;;CAQnB,YAAsB;AAClB,SAAO,SAAS;;;;;;;;CASpB,kBAAmB,KAAc,YAA0C;AACvE,MAAI,KAAK,QAAQ,kBACb,QAAO,KAAK,QAAQ,kBAAkB,KAAK,WAAW;AAG1D,MAAI,IAAI,QAAQ,OAAO,YAAY;GAC/B,QAAQ;GACR,WAAW;GACX,aAAa,QAAQ;AACjB,QAAI,UAAU,+BAA+B,IAAI;AACjD,QAAI,UAAU,gCAAgC,qBAAqB;AACnE,QAAI,UAAU,gCAAgC,8BAA8B;;GAEnF,CAAC,CAAC;;;;;;;CAQP,WAAY,KAAoC;AAC5C,SAAO,KAAK,QAAQ,WAAW,IAAI;;;;;;;;CASvC,gBACI,KACA,YACI;AACJ,MAAI,OAAO,eAAe,YAAY;AAClC,OAAI,IAAI,WAAW;AAEnB;;AAGJ,OAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,WAAW,CACnD,MAAK,MAAM,SAAS,QAChB,KAAI,QAAQ,QACR,KAAI,IAAI,OAAO,KAAK,KAAK,SAAS;AAC9B,OAAI,KAAK,UAAU,YAAY;AAC3B,UAAM,MAAM,KAAK,KAAK,KAAK;KAC7B;AACF,SAAM;IACR;MAEF,KAAI,IAAI,MAAM;;;;;;;;CAY9B,qBAAsB,KAAoB;AACtC,MAAI,KAAK,QAAQ,aACb,KAAI,IAAI,KAAK,QAAQ,aAAoC;;;;;;;;CAUjE,MAAO,KAAc,MAAoB;AACrC,MAAI,OAAO,YAAY;AACnB,UAAO,IAAI,CACP,CAAC,wBAAwB,QAAQ,EACjC,CAAC,oBAAoB,QAAQ,OAAO,CACvC,EAAE,IAAI;IACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-express",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express driver package for Arkstack providing Express-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@arkstack/contract": "^0.3.
|
|
39
|
+
"@arkstack/contract": "^0.3.8"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"express": "^5.2.1",
|
|
43
|
-
"@arkstack/common": "^0.3.
|
|
43
|
+
"@arkstack/common": "^0.3.8"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/express": "^5.0.6"
|