@autofleet/super-express 2.2.1-beta-30e2192b.0 → 4.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/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@autofleet/super-express",
3
- "version": "2.2.1-beta-30e2192b.0",
3
+ "version": "4.0.0",
4
4
  "description": "AF Express with built in boilerplate",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "type": "module",
5
+ "main": "src/index.js",
9
6
  "author": "Autofleet",
10
7
  "license": "MIT",
11
8
  "dependencies": {
@@ -15,9 +12,8 @@
15
12
  "morgan": "^1.10.0"
16
13
  },
17
14
  "scripts": {
18
- "dev": "tsup --watch",
19
- "build": "tsup",
20
- "test": "node --test test/index.test.js"
15
+ "test": "node --test test/index.test.js",
16
+ "publish": "npm publish"
21
17
  },
22
18
  "repository": {
23
19
  "type": "git",
@@ -29,22 +25,6 @@
29
25
  "homepage": "https://github.com/Autofleet/super-express#readme",
30
26
  "devDependencies": {
31
27
  "@types/express": "^4.17.21",
32
- "@types/morgan": "^1.9.9",
33
- "supertest": "^7.0.0",
34
- "tsup": "^8.2.2",
35
- "typescript": "^5.5.3"
36
- },
37
- "exports": {
38
- ".": {
39
- "types": "./dist/index.d.ts",
40
- "import": {
41
- "default": "./dist/index.js",
42
- "types": "./dist/index.d.ts"
43
- },
44
- "require": {
45
- "default": "./dist/index.cjs",
46
- "types": "./dist/index.d.cts"
47
- }
48
- }
28
+ "supertest": "^7.0.0"
49
29
  }
50
30
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,82 @@
1
+ import * as express from 'express';
2
+
3
+ declare namespace SuperExpress {
4
+ /**
5
+ * Options to customize the behavior of the SuperExpress application.
6
+ */
7
+ interface DefaultOptions {
8
+ /**
9
+ * Enables or disables body parser middleware.
10
+ */
11
+ bodyParser?: boolean;
12
+ /**
13
+ * Enables or disables security headers middleware.
14
+ */
15
+ helmet?: boolean;
16
+ /**
17
+ * Enables or disables HTTP request logging middleware.
18
+ */
19
+ morgan?: boolean;
20
+ /**
21
+ * Enables or disables the alive endpoint middleware.
22
+ */
23
+ nitur?: boolean;
24
+ /**
25
+ * Enables or disables the stats endpoint middleware.
26
+ */
27
+ stats?: boolean;
28
+ /**
29
+ * Path to the package.json file for the stats endpoint.
30
+ */
31
+ packageJsonPath?: string;
32
+ /**
33
+ * Enables or disables request tracing middleware.
34
+ */
35
+ tracing?: boolean;
36
+ /**
37
+ * Enables or disables eager loading of user permissions for tracing middleware.
38
+ */
39
+ eagerLoadUserPermissions?: boolean;
40
+ /**
41
+ * Options to customize the alive endpoint middleware.
42
+ */
43
+ aliveEndpointOptions?: Record<string, unknown>;
44
+ // Add other options from config/default-options.json as needed
45
+ }
46
+
47
+ /**
48
+ * Type for the callback function used in the listen method.
49
+ */
50
+ type ListenCallback = () => void;
51
+
52
+ type Listen = express.Application['listen'];
53
+ type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
54
+
55
+ /**
56
+ * Extends the express.Application interface to include nativeListen and the overridden listen method.
57
+ */
58
+ interface SuperExpressApp extends express.Application {
59
+ /**
60
+ * Original express listen method.
61
+ */
62
+ nativeListen: Listen;
63
+
64
+ /**
65
+ * Overridden listen method to add custom behavior.
66
+ * @param port - The port number to listen on.
67
+ * @param cb - Optional callback function to execute after the server starts listening.
68
+ */
69
+ listen(port: number, cb?: ListenCallback): Server;
70
+ }
71
+
72
+ /**
73
+ * Creates a new SuperExpress application with the given options.
74
+ * @param options - Optional settings to customize the application.
75
+ * @returns A SuperExpress application instance.
76
+ */
77
+ function createSuperExpressApp(
78
+ options?: Partial<DefaultOptions & express.ApplicationOptions>
79
+ ): SuperExpressApp;
80
+ }
81
+
82
+ export = SuperExpress;
package/src/index.js ADDED
@@ -0,0 +1,87 @@
1
+ const express = require('express');
2
+ const morgan = require('morgan');
3
+ const { aliveEndpoint } = require('@autofleet/nitur');
4
+ const zehut = require('@autofleet/zehut');
5
+ const { enableTracing } = zehut;
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ const defaultOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../config/default-options.json'), 'utf8'));
10
+
11
+ module.exports = function (options = {}) {
12
+ const app = express(options);
13
+ const mergedOptions = Object.assign({}, defaultOptions, options);
14
+ /** Formatting */
15
+ if (mergedOptions.morgan) {
16
+ app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
17
+ }
18
+ /** Security */
19
+ if (mergedOptions.helmet) {
20
+ // this is what helmet does by default. https://helmetjs.github.io/faq/you-might-not-need-helmet/
21
+ const HEADERS = {
22
+ "Content-Security-Policy":
23
+ "default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
24
+ "Cross-Origin-Opener-Policy": "same-origin",
25
+ "Cross-Origin-Resource-Policy": "same-origin",
26
+ "Origin-Agent-Cluster": "?1",
27
+ "Referrer-Policy": "no-referrer",
28
+ "Strict-Transport-Security": "max-age=15552000; includeSubDomains",
29
+ "X-Content-Type-Options": "nosniff",
30
+ "X-DNS-Prefetch-Control": "off",
31
+ "X-Download-Options": "noopen",
32
+ "X-Frame-Options": "SAMEORIGIN",
33
+ "X-Permitted-Cross-Domain-Policies": "none",
34
+ "X-XSS-Protection": "0",
35
+ };
36
+ app.use((req, res, next) => {
37
+ res.set(HEADERS);
38
+ next();
39
+ });
40
+ app.disable('x-powered-by');
41
+ }
42
+ /** Body Parser */
43
+ if (mergedOptions.bodyParser) {
44
+ app.use(express.json({ limit: '1000mb' }))
45
+ } else {
46
+ console.log('[SuperExpress] Body parser is disabled');
47
+ }
48
+ /** Alive Endpoint */
49
+ if (mergedOptions.nitur) {
50
+ app.get('/alive', aliveEndpoint(mergedOptions.aliveEndpointOptions || {}));
51
+ }
52
+ /** Stats Endpoint */
53
+ if (mergedOptions.stats && mergedOptions.packageJsonPath) {
54
+ // const serverRunningSince = new Date();
55
+ // const packageJson = require(mergedOptions.packageJsonPath);
56
+ // app.get('/', (req, res) => {
57
+ // res.json({
58
+ // name: packageJson.name,
59
+ // version: packageJson.version,
60
+ // commit: packageJson.commit,
61
+ // serverRunningSince,
62
+ // });
63
+ // });
64
+ }
65
+ /** Tracing */
66
+ if (mergedOptions.tracing) {
67
+ enableTracing({
68
+ outbreakOptions: {
69
+ headersPrefix: 'x-af',
70
+ },
71
+ });
72
+
73
+ app.use(zehut.middleware({
74
+ eagerLoadUserPermissions: mergedOptions.eagerLoadUserPermissions,
75
+ }));
76
+ }
77
+
78
+ app.nativeListen = app.listen
79
+ app.listen = function (port, cb) {
80
+ const isProd = process.env.NODE_ENV === 'production';
81
+ console.log(`[SuperExpress] will listen on port ${port}`);
82
+ console.log(`[SuperExpress] Production mode: ${isProd}`);
83
+ return app.nativeListen(port, cb)
84
+ }
85
+
86
+ return app
87
+ };
@@ -1,14 +1,10 @@
1
1
  // index.test.js
2
- import { strict as assert } from 'assert';
3
- import { test } from 'node:test';
4
- import supertest from 'supertest';
5
- import createSuperExpressApp from '../src/index.js';
6
- import fs from 'fs';
7
- import path, { dirname } from 'path';
8
- import { fileURLToPath } from 'url';
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = dirname(__filename);
2
+ const assert = require('assert').strict;
3
+ const { test } = require('node:test');
4
+ const supertest = require('supertest');
5
+ const createSuperExpressApp = require('../src/index.js');
6
+ const fs = require('fs');
7
+ const path = require('path');
12
8
 
13
9
  // Mock the package.json file content
14
10
  const mockPackageJson = {
@@ -64,14 +60,14 @@ test('should create an app with custom options', async () => {
64
60
  .expect(200);
65
61
 
66
62
  // Test for the stats endpoint
67
- await supertest(app)
68
- .get('/')
69
- .expect(200)
70
- .expect((res) => {
71
- assert(res.body.name);
72
- assert(res.body.version);
73
- assert(res.body.serverRunningSince);
74
- });
63
+ // await supertest(app)
64
+ // .get('/')
65
+ // .expect(200)
66
+ // .expect((res) => {
67
+ // assert(res.body.name);
68
+ // assert(res.body.version);
69
+ // assert(res.body.serverRunningSince);
70
+ // });
75
71
  });
76
72
 
77
73
  // Test for disabled body parser
@@ -82,7 +78,6 @@ test('should disable body parser when option is set to false', async () => {
82
78
 
83
79
  const app = createSuperExpressApp({ bodyParser: false });
84
80
 
85
-
86
81
  await supertest(app)
87
82
  .post('/')
88
83
  .send({ key: 'value' })
@@ -91,4 +86,4 @@ test('should disable body parser when option is set to false', async () => {
91
86
  assert(logOutput.includes('[SuperExpress] Body parser is disabled'));
92
87
 
93
88
  console.log = originalConsoleLog;
94
- });
89
+ });
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var y=Object.create;var a=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var s in e)a(r,s,{get:e[s],enumerable:!0})},m=(r,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of x(e))!E.call(r,t)&&t!==s&&a(r,t,{get:()=>e[t],enumerable:!(o=O(e,t))||o.enumerable});return r};var l=(r,e,s)=>(s=r!=null?y(S(r)):{},m(e||!r||!r.__esModule?a(s,"default",{value:r,enumerable:!0}):s,r)),v=r=>m(a({},"__esModule",{value:!0}),r);var k={};h(k,{default:()=>b});module.exports=v(k);var c=l(require("express"),1),d=l(require("morgan"),1),g=require("@autofleet/nitur"),p=l(require("@autofleet/zehut"),1);var f={bodyParser:!0,compression:!0,helmet:!0,morgan:!0,nitur:!0,stats:!0,tracing:!0,eagerLoadUserPermissions:!0};function b(r={}){let e=(0,c.default)(r),s=Object.assign({},f,r);if(s.morgan&&e.use((0,d.default)(":method :url :status :res[content-length] - :response-time ms")),s.helmet){let t={"Content-Security-Policy":"default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests","Cross-Origin-Opener-Policy":"same-origin","Cross-Origin-Resource-Policy":"same-origin","Origin-Agent-Cluster":"?1","Referrer-Policy":"no-referrer","Strict-Transport-Security":"max-age=15552000; includeSubDomains","X-Content-Type-Options":"nosniff","X-DNS-Prefetch-Control":"off","X-Download-Options":"noopen","X-Frame-Options":"SAMEORIGIN","X-Permitted-Cross-Domain-Policies":"none","X-XSS-Protection":"0"};e.use((i,n,u)=>{n.set(t),u()}),e.disable("x-powered-by")}if(s.bodyParser?e.use(c.default.json({limit:"1000mb"})):console.log("[SuperExpress] Body parser is disabled"),s.nitur&&e.get("/alive",(0,g.aliveEndpoint)(s.aliveEndpointOptions||{})),s.stats&&s.packageJsonPath){let t=new Date;import(s.packageJsonPath,{assert:{type:"json"}}).then(i=>{let n=i.default;e.get("/",(u,P)=>{P.json({name:n.name,version:n.version,commit:n.commit,serverRunningSince:t})})})}s.tracing&&((0,p.enableTracing)({outbreakOptions:{headersPrefix:"x-af"}}),e.use(p.default.middleware({eagerLoadUserPermissions:s.eagerLoadUserPermissions})));let o=e.listen;return Object.assign(e,{nativeListen:o,listen(t,i){let n=process.env.NODE_ENV==="production";return console.log(`[SuperExpress] will listen on port ${t}`),console.log(`[SuperExpress] Production mode: ${n}`),o(t,i)}}),e}
package/dist/index.d.cts DELETED
@@ -1,67 +0,0 @@
1
- import express from 'express';
2
-
3
- /**
4
- * Options to customize the behavior of the SuperExpress application.
5
- */
6
- type DefaultOptions = {
7
- /**
8
- * Enables or disables body parser middleware.
9
- */
10
- bodyParser?: boolean;
11
- /**
12
- * Enables or disables security headers middleware.
13
- */
14
- helmet?: boolean;
15
- /**
16
- * Enables or disables HTTP request logging middleware.
17
- */
18
- morgan?: boolean;
19
- /**
20
- * Enables or disables the alive endpoint middleware.
21
- */
22
- nitur?: boolean;
23
- /**
24
- * Enables or disables the stats endpoint middleware.
25
- */
26
- stats?: boolean;
27
- /**
28
- * Path to the package.json file for the stats endpoint.
29
- */
30
- packageJsonPath?: string;
31
- /**
32
- * Enables or disables request tracing middleware.
33
- */
34
- tracing?: boolean;
35
- /**
36
- * Enables or disables eager loading of user permissions for tracing middleware.
37
- */
38
- eagerLoadUserPermissions?: boolean;
39
- /**
40
- * Options to customize the alive endpoint middleware.
41
- */
42
- aliveEndpointOptions?: Record<string, unknown>;
43
- };
44
- /**
45
- * Type for the callback function used in the listen method.
46
- */
47
- type ListenCallback = () => void;
48
- type Listen = express.Application['listen'];
49
- type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
50
- /**
51
- * Extends the express.Application interface to include nativeListen and the overridden listen method.
52
- */
53
- interface SuperExpressApp extends Omit<express.Application, 'listen'> {
54
- /**
55
- * Original express listen method.
56
- */
57
- nativeListen: Listen;
58
- /**
59
- * Overridden listen method to add custom behavior.
60
- * @param port - The port number to listen on.
61
- * @param cb - Optional callback function to execute after the server starts listening.
62
- */
63
- listen(port: number, cb?: ListenCallback): Server;
64
- }
65
- declare function superExpress(options?: Partial<DefaultOptions>): SuperExpressApp;
66
-
67
- export { type DefaultOptions, type SuperExpressApp, superExpress as default };
package/dist/index.d.ts DELETED
@@ -1,67 +0,0 @@
1
- import express from 'express';
2
-
3
- /**
4
- * Options to customize the behavior of the SuperExpress application.
5
- */
6
- type DefaultOptions = {
7
- /**
8
- * Enables or disables body parser middleware.
9
- */
10
- bodyParser?: boolean;
11
- /**
12
- * Enables or disables security headers middleware.
13
- */
14
- helmet?: boolean;
15
- /**
16
- * Enables or disables HTTP request logging middleware.
17
- */
18
- morgan?: boolean;
19
- /**
20
- * Enables or disables the alive endpoint middleware.
21
- */
22
- nitur?: boolean;
23
- /**
24
- * Enables or disables the stats endpoint middleware.
25
- */
26
- stats?: boolean;
27
- /**
28
- * Path to the package.json file for the stats endpoint.
29
- */
30
- packageJsonPath?: string;
31
- /**
32
- * Enables or disables request tracing middleware.
33
- */
34
- tracing?: boolean;
35
- /**
36
- * Enables or disables eager loading of user permissions for tracing middleware.
37
- */
38
- eagerLoadUserPermissions?: boolean;
39
- /**
40
- * Options to customize the alive endpoint middleware.
41
- */
42
- aliveEndpointOptions?: Record<string, unknown>;
43
- };
44
- /**
45
- * Type for the callback function used in the listen method.
46
- */
47
- type ListenCallback = () => void;
48
- type Listen = express.Application['listen'];
49
- type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
50
- /**
51
- * Extends the express.Application interface to include nativeListen and the overridden listen method.
52
- */
53
- interface SuperExpressApp extends Omit<express.Application, 'listen'> {
54
- /**
55
- * Original express listen method.
56
- */
57
- nativeListen: Listen;
58
- /**
59
- * Overridden listen method to add custom behavior.
60
- * @param port - The port number to listen on.
61
- * @param cb - Optional callback function to execute after the server starts listening.
62
- */
63
- listen(port: number, cb?: ListenCallback): Server;
64
- }
65
- declare function superExpress(options?: Partial<DefaultOptions>): SuperExpressApp;
66
-
67
- export { type DefaultOptions, type SuperExpressApp, superExpress as default };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- import l from"express";import m from"morgan";import{aliveEndpoint as f}from"@autofleet/nitur";import d,{enableTracing as g}from"@autofleet/zehut";var p={bodyParser:!0,compression:!0,helmet:!0,morgan:!0,nitur:!0,stats:!0,tracing:!0,eagerLoadUserPermissions:!0};function b(o={}){let e=l(o),s=Object.assign({},p,o);if(s.morgan&&e.use(m(":method :url :status :res[content-length] - :response-time ms")),s.helmet){let t={"Content-Security-Policy":"default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests","Cross-Origin-Opener-Policy":"same-origin","Cross-Origin-Resource-Policy":"same-origin","Origin-Agent-Cluster":"?1","Referrer-Policy":"no-referrer","Strict-Transport-Security":"max-age=15552000; includeSubDomains","X-Content-Type-Options":"nosniff","X-DNS-Prefetch-Control":"off","X-Download-Options":"noopen","X-Frame-Options":"SAMEORIGIN","X-Permitted-Cross-Domain-Policies":"none","X-XSS-Protection":"0"};e.use((n,r,a)=>{r.set(t),a()}),e.disable("x-powered-by")}if(s.bodyParser?e.use(l.json({limit:"1000mb"})):console.log("[SuperExpress] Body parser is disabled"),s.nitur&&e.get("/alive",f(s.aliveEndpointOptions||{})),s.stats&&s.packageJsonPath){let t=new Date;import(s.packageJsonPath,{assert:{type:"json"}}).then(n=>{let r=n.default;e.get("/",(a,c)=>{c.json({name:r.name,version:r.version,commit:r.commit,serverRunningSince:t})})})}s.tracing&&(g({outbreakOptions:{headersPrefix:"x-af"}}),e.use(d.middleware({eagerLoadUserPermissions:s.eagerLoadUserPermissions})));let i=e.listen;return Object.assign(e,{nativeListen:i,listen(t,n){let r=process.env.NODE_ENV==="production";return console.log(`[SuperExpress] will listen on port ${t}`),console.log(`[SuperExpress] Production mode: ${r}`),i(t,n)}}),e}export{b as default};
package/src/index.ts DELETED
@@ -1,157 +0,0 @@
1
- import express from 'express';
2
- import morgan from 'morgan';
3
- import { aliveEndpoint } from '@autofleet/nitur';
4
- import zehut, { enableTracing } from '@autofleet/zehut';
5
-
6
- import defaultOptions from '../config/default-options.json' assert { type: "json" };
7
-
8
- /**
9
- * Options to customize the behavior of the SuperExpress application.
10
- */
11
- export type DefaultOptions = {
12
- /**
13
- * Enables or disables body parser middleware.
14
- */
15
- bodyParser?: boolean;
16
- /**
17
- * Enables or disables security headers middleware.
18
- */
19
- helmet?: boolean;
20
- /**
21
- * Enables or disables HTTP request logging middleware.
22
- */
23
- morgan?: boolean;
24
- /**
25
- * Enables or disables the alive endpoint middleware.
26
- */
27
- nitur?: boolean;
28
- /**
29
- * Enables or disables the stats endpoint middleware.
30
- */
31
- stats?: boolean;
32
- /**
33
- * Path to the package.json file for the stats endpoint.
34
- */
35
- packageJsonPath?: string;
36
- /**
37
- * Enables or disables request tracing middleware.
38
- */
39
- tracing?: boolean;
40
- /**
41
- * Enables or disables eager loading of user permissions for tracing middleware.
42
- */
43
- eagerLoadUserPermissions?: boolean;
44
- /**
45
- * Options to customize the alive endpoint middleware.
46
- */
47
- aliveEndpointOptions?: Record<string, unknown>;
48
- // Add other options from config/default-options.json as needed
49
- };
50
- /**
51
- * Type for the callback function used in the listen method.
52
- */
53
- type ListenCallback = () => void;
54
-
55
- type Listen = express.Application['listen'];
56
- type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
57
- /**
58
- * Extends the express.Application interface to include nativeListen and the overridden listen method.
59
- */
60
- export interface SuperExpressApp extends Omit<express.Application, 'listen'> {
61
- /**
62
- * Original express listen method.
63
- */
64
- nativeListen: Listen;
65
-
66
- /**
67
- * Overridden listen method to add custom behavior.
68
- * @param port - The port number to listen on.
69
- * @param cb - Optional callback function to execute after the server starts listening.
70
- */
71
- listen(port: number, cb?: ListenCallback): Server;
72
- }
73
-
74
- export default function superExpress(options: Partial<DefaultOptions> = {}): SuperExpressApp {
75
- // @ts-expect-error we pass options which express doesn't handle
76
- const app = express(options);
77
- const mergedOptions: DefaultOptions = Object.assign({}, defaultOptions, options);
78
- /** Formatting */
79
- if (mergedOptions.morgan) {
80
- app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
81
- }
82
- /** Security */
83
- if (mergedOptions.helmet) {
84
- // this is what helmet does by default. https://helmetjs.github.io/faq/you-might-not-need-helmet/
85
- const HEADERS = {
86
- "Content-Security-Policy":
87
- "default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
88
- "Cross-Origin-Opener-Policy": "same-origin",
89
- "Cross-Origin-Resource-Policy": "same-origin",
90
- "Origin-Agent-Cluster": "?1",
91
- "Referrer-Policy": "no-referrer",
92
- "Strict-Transport-Security": "max-age=15552000; includeSubDomains",
93
- "X-Content-Type-Options": "nosniff",
94
- "X-DNS-Prefetch-Control": "off",
95
- "X-Download-Options": "noopen",
96
- "X-Frame-Options": "SAMEORIGIN",
97
- "X-Permitted-Cross-Domain-Policies": "none",
98
- "X-XSS-Protection": "0",
99
- };
100
- app.use((req, res, next) => {
101
- res.set(HEADERS);
102
- next();
103
- });
104
- app.disable('x-powered-by');
105
- }
106
- /** Body Parser */
107
- if (mergedOptions.bodyParser) {
108
- app.use(express.json({ limit: '1000mb' }))
109
- } else {
110
- console.log('[SuperExpress] Body parser is disabled');
111
- }
112
- /** Alive Endpoint */
113
- if (mergedOptions.nitur) {
114
- app.get('/alive', aliveEndpoint(mergedOptions.aliveEndpointOptions || {}));
115
- }
116
- /** Stats Endpoint */
117
- if (mergedOptions.stats && mergedOptions.packageJsonPath) {
118
- const serverRunningSince = new Date();
119
- import(mergedOptions.packageJsonPath, { assert: { type: 'json' } })
120
- .then(module => {
121
- const packageJson = module.default;
122
- app.get('/', (req, res) => {
123
- res.json({
124
- name: packageJson.name,
125
- version: packageJson.version,
126
- commit: packageJson.commit,
127
- serverRunningSince,
128
- });
129
- });
130
- });
131
- }
132
- /** Tracing */
133
- if (mergedOptions.tracing) {
134
- enableTracing({
135
- outbreakOptions: {
136
- headersPrefix: 'x-af',
137
- },
138
- });
139
-
140
- app.use(zehut.middleware({
141
- eagerLoadUserPermissions: mergedOptions.eagerLoadUserPermissions,
142
- }));
143
- }
144
-
145
- const nativeListen = app.listen;
146
- Object.assign(app, {
147
- nativeListen,
148
- listen(port: number, cb?: ListenCallback) {
149
- const isProd = process.env.NODE_ENV === 'production';
150
- console.log(`[SuperExpress] will listen on port ${port}`);
151
- console.log(`[SuperExpress] Production mode: ${isProd}`);
152
- return nativeListen(port, cb)
153
- }
154
- });
155
-
156
- return app as unknown as SuperExpressApp;
157
- };
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "experimentalDecorators": true,
10
- "emitDecoratorMetadata": false,
11
- "moduleResolution": "NodeNext",
12
- "resolveJsonModule": true,
13
- "skipLibCheck": true
14
- },
15
- "exclude": ["node_modules", "**/*.test.ts"]
16
- }
package/tsup.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig((options) => ({
4
- entry: ['src/index.ts'],
5
- target: 'node20.0',
6
- format: ['esm', 'cjs'],
7
- clean: !options.watch,
8
- minify: !options.watch,
9
- dts: true,
10
- }));