@autofleet/super-express 2.2.1-beta-6c740761.2 → 2.2.1-beta-30e2192b.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/dist/index.cjs +1 -0
- package/dist/index.d.cts +67 -0
- package/{src → dist}/index.d.ts +4 -14
- package/dist/index.js +1 -0
- package/package.json +16 -12
- package/src/index.ts +157 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +10 -0
- package/src/index.cjs +0 -86
- package/src/index.d.cts +0 -10
- package/src/index.mjs +0 -7
package/dist/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
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
ADDED
@@ -0,0 +1,67 @@
|
|
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/{src → dist}/index.d.ts
RENAMED
@@ -3,7 +3,7 @@ import express from 'express';
|
|
3
3
|
/**
|
4
4
|
* Options to customize the behavior of the SuperExpress application.
|
5
5
|
*/
|
6
|
-
|
6
|
+
type DefaultOptions = {
|
7
7
|
/**
|
8
8
|
* Enables or disables body parser middleware.
|
9
9
|
*/
|
@@ -40,25 +40,21 @@ export type DefaultOptions = {
|
|
40
40
|
* Options to customize the alive endpoint middleware.
|
41
41
|
*/
|
42
42
|
aliveEndpointOptions?: Record<string, unknown>;
|
43
|
-
// Add other options from config/default-options.json as needed
|
44
43
|
};
|
45
|
-
|
46
44
|
/**
|
47
45
|
* Type for the callback function used in the listen method.
|
48
46
|
*/
|
49
47
|
type ListenCallback = () => void;
|
50
|
-
|
51
48
|
type Listen = express.Application['listen'];
|
52
49
|
type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
|
53
50
|
/**
|
54
51
|
* Extends the express.Application interface to include nativeListen and the overridden listen method.
|
55
52
|
*/
|
56
|
-
|
53
|
+
interface SuperExpressApp extends Omit<express.Application, 'listen'> {
|
57
54
|
/**
|
58
55
|
* Original express listen method.
|
59
56
|
*/
|
60
57
|
nativeListen: Listen;
|
61
|
-
|
62
58
|
/**
|
63
59
|
* Overridden listen method to add custom behavior.
|
64
60
|
* @param port - The port number to listen on.
|
@@ -66,12 +62,6 @@ export interface SuperExpressApp extends Omit<express.Application, 'listen'> {
|
|
66
62
|
*/
|
67
63
|
listen(port: number, cb?: ListenCallback): Server;
|
68
64
|
}
|
65
|
+
declare function superExpress(options?: Partial<DefaultOptions>): SuperExpressApp;
|
69
66
|
|
70
|
-
|
71
|
-
* Creates a new SuperExpress application with the given options.
|
72
|
-
* @param options - Optional settings to customize the application.
|
73
|
-
* @returns A SuperExpress application instance.
|
74
|
-
*/
|
75
|
-
export default function createSuperExpressApp(
|
76
|
-
options?: Partial<DefaultOptions>
|
77
|
-
): SuperExpressApp;
|
67
|
+
export { type DefaultOptions, type SuperExpressApp, superExpress as default };
|
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
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/package.json
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "@autofleet/super-express",
|
3
|
-
"version": "2.2.1-beta-
|
3
|
+
"version": "2.2.1-beta-30e2192b.0",
|
4
4
|
"description": "AF Express with built in boilerplate",
|
5
|
-
"main": "
|
6
|
-
"module": "
|
7
|
-
"types": "
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"module": "dist/index.js",
|
7
|
+
"types": "dist/index.d.ts",
|
8
8
|
"type": "module",
|
9
9
|
"author": "Autofleet",
|
10
10
|
"license": "MIT",
|
@@ -15,9 +15,9 @@
|
|
15
15
|
"morgan": "^1.10.0"
|
16
16
|
},
|
17
17
|
"scripts": {
|
18
|
-
"
|
19
|
-
"build": "",
|
20
|
-
"
|
18
|
+
"dev": "tsup --watch",
|
19
|
+
"build": "tsup",
|
20
|
+
"test": "node --test test/index.test.js"
|
21
21
|
},
|
22
22
|
"repository": {
|
23
23
|
"type": "git",
|
@@ -29,17 +29,21 @@
|
|
29
29
|
"homepage": "https://github.com/Autofleet/super-express#readme",
|
30
30
|
"devDependencies": {
|
31
31
|
"@types/express": "^4.17.21",
|
32
|
-
"
|
32
|
+
"@types/morgan": "^1.9.9",
|
33
|
+
"supertest": "^7.0.0",
|
34
|
+
"tsup": "^8.2.2",
|
35
|
+
"typescript": "^5.5.3"
|
33
36
|
},
|
34
37
|
"exports": {
|
35
38
|
".": {
|
39
|
+
"types": "./dist/index.d.ts",
|
36
40
|
"import": {
|
37
|
-
"default": "./
|
38
|
-
"types": "./
|
41
|
+
"default": "./dist/index.js",
|
42
|
+
"types": "./dist/index.d.ts"
|
39
43
|
},
|
40
44
|
"require": {
|
41
|
-
"default": "./
|
42
|
-
"types": "./
|
45
|
+
"default": "./dist/index.cjs",
|
46
|
+
"types": "./dist/index.d.cts"
|
43
47
|
}
|
44
48
|
}
|
45
49
|
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,157 @@
|
|
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
ADDED
@@ -0,0 +1,16 @@
|
|
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
ADDED
package/src/index.cjs
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
const express = require('express');
|
2
|
-
const morgan = require('morgan');
|
3
|
-
const { aliveEndpoint } = require('@autofleet/nitur');
|
4
|
-
const { default: zehut, enableTracing } = require('@autofleet/zehut');
|
5
|
-
const defaultOptions = require('../config/default-options.json');
|
6
|
-
|
7
|
-
module.exports = function superExpress(options = {}) {
|
8
|
-
const app = express(options);
|
9
|
-
const mergedOptions = Object.assign({}, defaultOptions, options);
|
10
|
-
/** Formatting */
|
11
|
-
if (mergedOptions.morgan) {
|
12
|
-
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
|
13
|
-
}
|
14
|
-
/** Security */
|
15
|
-
if (mergedOptions.helmet) {
|
16
|
-
// this is what helmet does by default. https://helmetjs.github.io/faq/you-might-not-need-helmet/
|
17
|
-
const HEADERS = {
|
18
|
-
"Content-Security-Policy":
|
19
|
-
"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",
|
20
|
-
"Cross-Origin-Opener-Policy": "same-origin",
|
21
|
-
"Cross-Origin-Resource-Policy": "same-origin",
|
22
|
-
"Origin-Agent-Cluster": "?1",
|
23
|
-
"Referrer-Policy": "no-referrer",
|
24
|
-
"Strict-Transport-Security": "max-age=15552000; includeSubDomains",
|
25
|
-
"X-Content-Type-Options": "nosniff",
|
26
|
-
"X-DNS-Prefetch-Control": "off",
|
27
|
-
"X-Download-Options": "noopen",
|
28
|
-
"X-Frame-Options": "SAMEORIGIN",
|
29
|
-
"X-Permitted-Cross-Domain-Policies": "none",
|
30
|
-
"X-XSS-Protection": "0",
|
31
|
-
};
|
32
|
-
app.use((req, res, next) => {
|
33
|
-
res.set(HEADERS);
|
34
|
-
next();
|
35
|
-
});
|
36
|
-
app.disable('x-powered-by');
|
37
|
-
}
|
38
|
-
/** Body Parser */
|
39
|
-
if (mergedOptions.bodyParser) {
|
40
|
-
app.use(express.json({ limit: '1000mb' }))
|
41
|
-
} else {
|
42
|
-
console.log('[SuperExpress] Body parser is disabled');
|
43
|
-
}
|
44
|
-
/** Alive Endpoint */
|
45
|
-
if (mergedOptions.nitur) {
|
46
|
-
app.get('/alive', aliveEndpoint(mergedOptions.aliveEndpointOptions || {}));
|
47
|
-
}
|
48
|
-
/** Stats Endpoint */
|
49
|
-
if (mergedOptions.stats && mergedOptions.packageJsonPath) {
|
50
|
-
const serverRunningSince = new Date();
|
51
|
-
import(mergedOptions.packageJsonPath, { assert: { type: 'json' } })
|
52
|
-
.then(module => {
|
53
|
-
const packageJson = module.default;
|
54
|
-
app.get('/', (req, res) => {
|
55
|
-
res.json({
|
56
|
-
name: packageJson.name,
|
57
|
-
version: packageJson.version,
|
58
|
-
commit: packageJson.commit,
|
59
|
-
serverRunningSince,
|
60
|
-
});
|
61
|
-
});
|
62
|
-
});
|
63
|
-
}
|
64
|
-
/** Tracing */
|
65
|
-
if (mergedOptions.tracing) {
|
66
|
-
enableTracing({
|
67
|
-
outbreakOptions: {
|
68
|
-
headersPrefix: 'x-af',
|
69
|
-
},
|
70
|
-
});
|
71
|
-
|
72
|
-
app.use(zehut.middleware({
|
73
|
-
eagerLoadUserPermissions: mergedOptions.eagerLoadUserPermissions,
|
74
|
-
}));
|
75
|
-
}
|
76
|
-
|
77
|
-
app.nativeListen = app.listen
|
78
|
-
app.listen = function (port, cb) {
|
79
|
-
const isProd = process.env.NODE_ENV === 'production';
|
80
|
-
console.log(`[SuperExpress] will listen on port ${port}`);
|
81
|
-
console.log(`[SuperExpress] Production mode: ${isProd}`);
|
82
|
-
return app.nativeListen(port, cb)
|
83
|
-
}
|
84
|
-
|
85
|
-
return app
|
86
|
-
};
|
package/src/index.d.cts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import type createSuperExpressApp from './index.d.ts';
|
2
|
-
import type { DefaultOptions as Options, SuperExpressApp as _SuperExpressApp } from './index.d.ts';
|
3
|
-
|
4
|
-
declare namespace createSuperExpressApp {
|
5
|
-
export type DefaultOptions = Options;
|
6
|
-
export type SuperExpressApp = _SuperExpressApp;
|
7
|
-
|
8
|
-
}
|
9
|
-
|
10
|
-
export = createSuperExpressApp;
|