-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
323 additions
and
19 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@ | ||
const returnBody = (value, res) => { | ||
try { | ||
res.json(JSON.parse(value)); | ||
} catch (e) { | ||
res.json(value); | ||
} | ||
} | ||
|
||
module.exports = (req, res, next) => { | ||
if (req.headers.echo_body) { | ||
returnBody(req.headers.echo_body, res); | ||
} else if (req.query.echo_body) { | ||
returnBody(req.query.echo_body, res); | ||
} else { | ||
next(); | ||
} | ||
} |
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,13 @@ | ||
const setupHttpCode = (value, res) => { | ||
if (value && | ||
value >= 200 && | ||
value <= 599) { | ||
res.status(value); | ||
} | ||
} | ||
|
||
module.exports = (req, res, next) => { | ||
setupHttpCode(req.headers.echo_code, res); | ||
setupHttpCode(req.query.echo_code, res); | ||
next(); | ||
} |
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,13 @@ | ||
const config = require('../nconf'); | ||
|
||
module.exports = (req, res, next) => { | ||
if (!config.get('enable:environment')) { | ||
next(); | ||
} else if (req.headers.echo_env_body) { | ||
res.json(process.env[req.headers.echo_env_body]); | ||
} else if (req.query.echo_env_body) { | ||
res.json(process.env[req.query.echo_env_body]); | ||
} else { | ||
next(); | ||
} | ||
} |
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,8 @@ | ||
const config = require('../nconf'); | ||
|
||
module.exports = (req, res, next) => { | ||
if (req.originalUrl != "/ping" || !config.get('logs:ignore:ping')) { | ||
console.log(`${Date.now()} | [${req.method}] - ${req.protocol}://${req.get('host')}${req.originalUrl}`); | ||
} | ||
next(); | ||
} |
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,46 @@ | ||
const assert = require('assert'); | ||
const request = require('supertest'); | ||
|
||
describe('Custom Body', function () { | ||
var server; | ||
beforeEach(function () { | ||
server = require('../src/app'); | ||
}); | ||
afterEach(function () { | ||
server.close(); | ||
}); | ||
it('Text with Header', (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_BODY', 'Example text') | ||
.expect(function (res) { | ||
assert.equal(res.body, "Example text") | ||
}) | ||
.expect(200, done); | ||
}); | ||
it('Json with Header', (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_BODY', '{"example": "json"}') | ||
.expect(function (res) { | ||
assert.equal(res.body.example, "json") | ||
}) | ||
.expect(200, done); | ||
}); | ||
it('Text with Query', (done) => { | ||
request(server) | ||
.get('/?echo_body=Example text') | ||
.expect(function (res) { | ||
assert.equal(res.body, "Example text") | ||
}) | ||
.expect(200, done); | ||
}); | ||
it('Json with Query', (done) => { | ||
request(server) | ||
.get('/?echo_body={"example": "json"}') | ||
.expect(function (res) { | ||
assert.equal(res.body.example, "json") | ||
}) | ||
.expect(200, done); | ||
}); | ||
}); |
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,93 @@ | ||
const request = require('supertest'); | ||
|
||
describe('Custom HTTP Code', function () { | ||
var server; | ||
beforeEach(function () { | ||
server = require('../src/app'); | ||
}); | ||
afterEach(function () { | ||
server.close(); | ||
}); | ||
it("Default 200", (done) => { | ||
request(server) | ||
.get('/') | ||
.expect(200, done); | ||
}); | ||
it("Custom 200", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 200) | ||
.expect(200, done); | ||
}); | ||
it("Custom 200 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=200') | ||
.expect(200, done); | ||
}); | ||
it("Custom 201", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 201) | ||
.expect(201, done); | ||
}); | ||
it("Custom 201 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=201') | ||
.expect(201, done); | ||
}); | ||
it("Custom 300", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 300) | ||
.expect(300, done); | ||
}); | ||
it("Custom 300 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=300') | ||
.expect(300, done); | ||
}); | ||
it("Custom 400", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 400) | ||
.expect(400, done); | ||
}); | ||
it("Custom 400 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=400') | ||
.expect(400, done); | ||
}); | ||
it("Custom 401", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 401) | ||
.expect(401, done); | ||
}); | ||
it("Custom 401 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=401') | ||
.expect(401, done); | ||
}); | ||
it("Custom 404", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 404) | ||
.expect(404, done); | ||
}); | ||
it("Custom 404 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=404') | ||
.expect(404, done); | ||
}); | ||
it("Custom 500", (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_CODE', 500) | ||
.expect(500, done); | ||
}); | ||
it("Custom 500 with Query", (done) => { | ||
request(server) | ||
.get('/?echo_code=500') | ||
.expect(500, done); | ||
}); | ||
}); |
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,29 @@ | ||
const assert = require('assert'); | ||
const request = require('supertest'); | ||
|
||
describe('Custom Body with Environment', function () { | ||
var server; | ||
beforeEach(function () { | ||
server = require('../src/app'); | ||
}); | ||
afterEach(function () { | ||
server.close(); | ||
}); | ||
it('LANG', (done) => { | ||
request(server) | ||
.get('/') | ||
.set('ECHO_ENV_BODY', 'LANG') | ||
.expect(function (res) { | ||
assert.equal(res.body, process.env["LANG"]) | ||
}) | ||
.expect(200, done); | ||
}); | ||
it('LANG with Query', (done) => { | ||
request(server) | ||
.get('/?echo_env_body=LANG') | ||
.expect(function (res) { | ||
assert.equal(res.body, process.env["LANG"]) | ||
}) | ||
.expect(200, done); | ||
}); | ||
}); |
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,20 @@ | ||
const assert = require('assert'); | ||
const request = require('supertest'); | ||
|
||
describe('Environment', function () { | ||
var server; | ||
beforeEach(function () { | ||
server = require('../src/app'); | ||
}); | ||
afterEach(function () { | ||
server.close(); | ||
}); | ||
it('Equal', (done) => { | ||
request(server) | ||
.get('/') | ||
.expect(function (res) { | ||
assert.equal(res.body.environment[0], process.env[0]) | ||
}) | ||
.expect(200, done); | ||
}); | ||
}); |