Skip to content
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

Move health endpoint #206

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 56 additions & 103 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "soul-cli",
"version": "0.8.0",
"version": "0.8.1",
"description": "A SQLite REST and Realtime server",
"main": "src/server.js",
"bin": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"eslint-config-prettier": "^9.0.0",
"husky": "^8.0.3",
"jest": "^29.4.3",
"nodemon": "^2.0.20",
"nodemon": "^3.1.3",
"prettier": "3.1.0",
"supertest": "^6.3.3",
"swagger-autogen": "^2.23.1"
Expand Down
11 changes: 11 additions & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const root = async (req, res) => {
});
};

const health = async (req, res) => {
/*
#swagger.tags = ['Root']
#swagger.summary = 'Health Check'
#swagger.description = 'Endpoint to return server health status'
*/

res.send('OK');
};

module.exports = {
root,
health,
};
8 changes: 8 additions & 0 deletions src/controllers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ describe('Root Endpoints', () => {
expect(res.body.data).toHaveProperty('timestamp');
});
});

describe('Health Endpoints', () => {
it('GET /health should return server version and timestamp', async () => {
const res = await requestWithSupertest.get('/api/health');
expect(res.status).toEqual(200);
expect(res.type).toEqual(expect.stringContaining('text'));
});
});
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ const {

const { runCLICommands } = require('./commands');
const { authConstants } = require('./constants');

const app = express();
app.get('/health', (req, res) => {
res.send('OK');
});

app.use(bodyParser.json());
app.use(cookieParser());
Expand Down
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const controllers = require('../controllers/index');
const router = express.Router();

router.get('/', controllers.root);
router.get('/health', controllers.health);

module.exports = router;
14 changes: 8 additions & 6 deletions src/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/health": {
"/api/": {
"get": {
"description": "",
"tags": ["Root"],
"summary": "Timestamp",
"description": "Endpoint to return server timestamp",
"parameters": [],
"responses": {
"200": {
Expand All @@ -41,11 +43,11 @@
}
}
},
"/api/": {
"/api/health": {
"get": {
"tags": ["Root"],
"summary": "Timestamp",
"description": "Endpoint to return server timestamp",
"summary": "Health Check",
"description": "Endpoint to return server health status",
"parameters": [],
"responses": {
"200": {
Expand Down Expand Up @@ -865,7 +867,7 @@
"properties": {
"message": {
"type": "string",
"example": "This password is weak, please use another password"
"example": "This password is weak, it should be at least 8 characters long and contain a combination of lowercase letters, uppercase letters, numbers, and special characters"
}
}
},
Expand Down
Loading