Comparing version 6.8.0 to 7.0.0
import type { ConfigurationInput, Lightship } from '../types'; | ||
declare const _default: (userConfiguration?: ConfigurationInput | undefined) => Lightship; | ||
declare const _default: (userConfiguration?: ConfigurationInput | undefined) => Promise<Lightship>; | ||
export default _default; |
@@ -9,4 +9,3 @@ "use strict"; | ||
const delay_1 = __importDefault(require("delay")); | ||
const express_1 = __importDefault(require("express")); | ||
const http_terminator_1 = require("http-terminator"); | ||
const fastify_1 = __importDefault(require("fastify")); | ||
const serialize_error_1 = require("serialize-error"); | ||
@@ -38,3 +37,3 @@ const Logger_1 = __importDefault(require("../Logger")); | ||
}; | ||
exports.default = (userConfiguration) => { | ||
exports.default = async (userConfiguration) => { | ||
let blockingTasks = []; | ||
@@ -67,51 +66,51 @@ let resolveFirstReady; | ||
}; | ||
const app = (0, express_1.default)(); | ||
const modeIsLocal = configuration.detectKubernetes === true && (0, utilities_1.isKubernetes)() === false; | ||
const server = app.listen(modeIsLocal ? undefined : configuration.port, () => { | ||
const address = server.address(); | ||
log.info('Lightship HTTP service is running on port %s', address.port); | ||
const app = (0, fastify_1.default)(); | ||
app.addHook('onError', (request, reply, error, done) => { | ||
// Only send Sentry errors when not in development | ||
// eslint-disable-next-line node/no-process-env | ||
if (process.env.NODE_ENV !== 'development') { | ||
(0, node_1.captureException)(error); | ||
} | ||
done(); | ||
}); | ||
const httpTerminator = (0, http_terminator_1.createHttpTerminator)({ | ||
server, | ||
}); | ||
app.use(node_1.Handlers.requestHandler()); | ||
app.get('/health', (incomingMessage, serverResponse) => { | ||
app.get('/health', (request, reply) => { | ||
if (serverIsShuttingDown) { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(states_1.SERVER_IS_SHUTTING_DOWN); | ||
} | ||
else if (serverIsReady) { | ||
serverResponse | ||
void reply | ||
.send(states_1.SERVER_IS_READY); | ||
} | ||
else { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(states_1.SERVER_IS_NOT_READY); | ||
} | ||
}); | ||
app.get('/live', (incomingMessage, serverResponse) => { | ||
app.get('/live', (request, reply) => { | ||
if (serverIsShuttingDown) { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(states_1.SERVER_IS_SHUTTING_DOWN); | ||
} | ||
else { | ||
serverResponse | ||
void reply | ||
.send(states_1.SERVER_IS_NOT_SHUTTING_DOWN); | ||
} | ||
}); | ||
app.get('/ready', (incomingMessage, serverResponse) => { | ||
app.get('/ready', (request, reply) => { | ||
if (isServerReady()) { | ||
serverResponse | ||
void reply | ||
.send(states_1.SERVER_IS_READY); | ||
} | ||
else { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(states_1.SERVER_IS_NOT_READY); | ||
} | ||
}); | ||
app.use(node_1.Handlers.errorHandler()); | ||
const modeIsLocal = configuration.detectKubernetes === true && (0, utilities_1.isKubernetes)() === false; | ||
await app.listen(modeIsLocal ? 0 : configuration.port, '0.0.0.0'); | ||
const signalNotReady = () => { | ||
@@ -205,3 +204,3 @@ if (serverIsReady === false) { | ||
log.debug('all shutdown handlers have run to completion; proceeding to terminate the Node.js process'); | ||
await httpTerminator.terminate(); | ||
void app.close(); | ||
setTimeout(() => { | ||
@@ -262,3 +261,3 @@ log.warn('process did not exit on its own; investigate what is keeping the event loop active'); | ||
}, | ||
server, | ||
server: app.server, | ||
shutdown: () => { | ||
@@ -265,0 +264,0 @@ return shutdown(false); |
@@ -21,4 +21,3 @@ { | ||
"delay": "^5.0.0", | ||
"express": "^4.17.1", | ||
"http-terminator": "^3.0.4", | ||
"fastify": "^3.27.2", | ||
"roarr": "^7.8.0", | ||
@@ -30,3 +29,2 @@ "serialize-error": "^8.1.0" | ||
"@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"@types/express": "^4.17.13", | ||
"@types/http-terminator": "^2.0.2", | ||
@@ -71,7 +69,7 @@ "@types/node": "^16.9.2", | ||
"generate-readme": "gitdown ./.README/README.md --output-file ./README.md", | ||
"lint": "eslint ./src ./test --ext .js --ext .ts", | ||
"lint": "eslint ./src ./test", | ||
"test": "NODE_ENV=test ava --verbose --serial", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"version": "6.8.0" | ||
"version": "7.0.0" | ||
} |
@@ -109,3 +109,3 @@ <a name="lightship"></a> | ||
const lightship: Lightship = createLightship(configuration); | ||
const lightship: Lightship = await createLightship(configuration); | ||
@@ -228,3 +228,3 @@ ``` | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -265,3 +265,3 @@ lightship.queueBlockingTask(new Promise((resolve) => { | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -333,3 +333,3 @@ const app = express(); | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -376,3 +376,3 @@ lightship.registerShutdownHandler(() => { | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -433,3 +433,3 @@ lightship.registerShutdownHandler(() => { | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -462,3 +462,3 @@ lightship.registerShutdownHandler(async () => { | ||
```js | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -620,3 +620,3 @@ const beacon = lightship.createBeacon(); | ||
const lightship = createLightship(); | ||
const lightship = await createLightship(); | ||
@@ -623,0 +623,0 @@ lightship.registerShutdownHandler(() => { |
import { | ||
EventEmitter, | ||
} from 'events'; | ||
import type { | ||
AddressInfo, | ||
} from 'net'; | ||
import { | ||
Handlers as SentryHandlers, | ||
captureException, | ||
} from '@sentry/node'; | ||
import delay from 'delay'; | ||
import express from 'express'; | ||
import createFastify from 'fastify'; | ||
import { | ||
createHttpTerminator, | ||
} from 'http-terminator'; | ||
import { | ||
serializeError, | ||
@@ -68,3 +62,3 @@ } from 'serialize-error'; | ||
export default (userConfiguration?: ConfigurationInput): Lightship => { | ||
export default async (userConfiguration?: ConfigurationInput): Promise<Lightship> => { | ||
let blockingTasks: BlockingTask[] = []; | ||
@@ -109,28 +103,25 @@ | ||
const app = express(); | ||
const app = createFastify(); | ||
const modeIsLocal = configuration.detectKubernetes === true && isKubernetes() === false; | ||
app.addHook('onError', (request, reply, error, done) => { | ||
// Only send Sentry errors when not in development | ||
// eslint-disable-next-line node/no-process-env | ||
if (process.env.NODE_ENV !== 'development') { | ||
captureException(error); | ||
} | ||
const server = app.listen(modeIsLocal ? undefined : configuration.port, () => { | ||
const address = server.address() as AddressInfo; | ||
log.info('Lightship HTTP service is running on port %s', address.port); | ||
done(); | ||
}); | ||
const httpTerminator = createHttpTerminator({ | ||
server, | ||
}); | ||
app.use(SentryHandlers.requestHandler()); | ||
app.get('/health', (incomingMessage, serverResponse) => { | ||
app.get('/health', (request, reply) => { | ||
if (serverIsShuttingDown) { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(SERVER_IS_SHUTTING_DOWN); | ||
} else if (serverIsReady) { | ||
serverResponse | ||
void reply | ||
.send(SERVER_IS_READY); | ||
} else { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(SERVER_IS_NOT_READY); | ||
@@ -140,9 +131,9 @@ } | ||
app.get('/live', (incomingMessage, serverResponse) => { | ||
app.get('/live', (request, reply) => { | ||
if (serverIsShuttingDown) { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(SERVER_IS_SHUTTING_DOWN); | ||
} else { | ||
serverResponse | ||
void reply | ||
.send(SERVER_IS_NOT_SHUTTING_DOWN); | ||
@@ -152,9 +143,9 @@ } | ||
app.get('/ready', (incomingMessage, serverResponse) => { | ||
app.get('/ready', (request, reply) => { | ||
if (isServerReady()) { | ||
serverResponse | ||
void reply | ||
.send(SERVER_IS_READY); | ||
} else { | ||
serverResponse | ||
.status(500) | ||
void reply | ||
.code(500) | ||
.send(SERVER_IS_NOT_READY); | ||
@@ -164,4 +155,6 @@ } | ||
app.use(SentryHandlers.errorHandler()); | ||
const modeIsLocal = configuration.detectKubernetes === true && isKubernetes() === false; | ||
await app.listen(modeIsLocal ? 0 : configuration.port, '0.0.0.0'); | ||
const signalNotReady = () => { | ||
@@ -287,3 +280,3 @@ if (serverIsReady === false) { | ||
await httpTerminator.terminate(); | ||
void app.close(); | ||
@@ -357,3 +350,3 @@ setTimeout(() => { | ||
}, | ||
server, | ||
server: app.server, | ||
shutdown: () => { | ||
@@ -360,0 +353,0 @@ return shutdown(false); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
5
17
0
55932
784
2
+ Addedfastify@^3.27.2
+ Added@fastify/ajv-compiler@1.1.0(transitive)
+ Added@fastify/error@2.0.0(transitive)
+ Addedabstract-logging@2.0.1(transitive)
+ Addedajv@6.12.68.17.1(transitive)
+ Addedarchy@1.0.0(transitive)
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedavvio@7.2.5(transitive)
+ Addedcookie@0.5.0(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedfast-content-type-parse@1.1.0(transitive)
+ Addedfast-decode-uri-component@1.0.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-json-stringify@2.7.13(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addedfastify@3.29.5(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfind-my-way@4.5.1(transitive)
+ Addedflatstr@1.0.12(transitive)
+ Addedjson-schema-traverse@0.4.11.0.0(transitive)
+ Addedlight-my-request@4.12.0(transitive)
+ Addedpino@6.14.0(transitive)
+ Addedpino-std-serializers@3.2.0(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedret@0.2.2(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrfdc@1.4.1(transitive)
+ Addedsafe-regex2@2.0.0(transitive)
+ Addedsecure-json-parse@2.7.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsemver-store@0.3.0(transitive)
+ Addedset-cookie-parser@2.7.1(transitive)
+ Addedsonic-boom@1.4.1(transitive)
+ Addedstring-similarity@4.0.4(transitive)
+ Addedtiny-lru@8.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)
- Removedexpress@^4.17.1
- Removedhttp-terminator@^3.0.4
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.7.1(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.1(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removedhttp-terminator@3.2.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.0(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedp-wait-for@3.2.0(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.10(transitive)
- Removedqs@6.13.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtype-fest@2.19.0(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)