-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] HTTP API healthcheck #413
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8b33c51
Implemented HttpManager for Express.js
rennokki 600d500
⏲ Uptime endpoint
rennokki a4098b4
Added ENABLE_HTTP_API and HTTP_API_PORT for the API
rennokki 6e8a307
Fixed default port number
rennokki 53e96ec
🔄 reposition env variables
idinium96 74c1f5b
end of file
rennokki 5ce6234
Reverted uptime changes
rennokki 6a67423
Conditionally initialize & run the API
rennokki 81504bd
Removed server member.
rennokki 1251430
Setting default port to 3001
rennokki d2e09a3
Setting default 3001 on the options
rennokki 94d8048
Added info when starting the HTTP server.
rennokki 8b84c98
Resolve after log.
rennokki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
|
||
import bodyParser from 'body-parser'; | ||
import express from 'express'; | ||
import log from '../lib/logger'; | ||
import Options from './Options'; | ||
|
||
export default class HttpManager { | ||
/** | ||
* The Express.js app. | ||
*/ | ||
protected app: express.Application; | ||
|
||
/** | ||
* The Express.js server app. | ||
*/ | ||
public server; | ||
rennokki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Initialize the HTTP manager. | ||
* | ||
* @param options - The options list. | ||
*/ | ||
constructor(protected options: Options) { | ||
this.app = express(); | ||
this.app.use(bodyParser.json()); | ||
this.app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
this.registerRoutes(); | ||
} | ||
|
||
/** | ||
* Register the routes. | ||
*/ | ||
protected registerRoutes(): void { | ||
this.app.get('/health', (req, res) => res.send('OK')); | ||
this.app.get('/uptime', (req, res) => res.json({ uptime: process.uptime() })); | ||
} | ||
|
||
/** | ||
* Start the server. | ||
*/ | ||
start(): Promise<void> { | ||
return new Promise(resolve => { | ||
this.server = this.app.listen(this.options.httpApiPort, () => { | ||
resolve(); | ||
log.debug(`HTTP Server started: http://127.0.0.1:${this.options.httpApiPort}`); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ TIME_ADDITIONAL_NOTES="" | |
|
||
DEBUG=true | ||
DEBUG_FILE=true | ||
|
||
ENABLE_HTTP_API=false | ||
HTTP_API_PORT=80 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about importing only if enabled, to reduce memory usage slightly, but this is not that important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES6 and TS don't allow importing with
import from
within classes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, either use
require
or let it be like it is now