forked from openshift-knative/showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify JSON response (openshift-knative#10)
The simplified response is so it contains a short JSON, and the additional data is delivered via headers: ``` HTTP/1.1 200 OK content-length: 52 Content-Type: application/json Server: Quarkus/2.13.5.Final-redhat-00002 Java/17.0.5 X-Config: {"sink":"http://localhost:38859","greet":"Welcome","delay":0} X-Version: feature-event-receiver-8540b9b { "artifact":"knative-showcase", "greeting":"Welcome" } ```
- Loading branch information
Showing
58 changed files
with
649 additions
and
494 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
K_SINK=http://localhost:31111 | ||
PORT=8080 | ||
GREETING=Hello | ||
DELAY=0 | ||
CONTAINER_BASENAME=quay.io/openshift-knative/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,21 +1,54 @@ | ||
const Joi = require('joi') | ||
|
||
function sink() { | ||
return process.env.K_SINK | ||
return process.env.K_SINK || 'http://localhost:31111' | ||
} | ||
|
||
function greeting() { | ||
return process.env.GREETING | ||
function greet() { | ||
return process.env.GREET || 'Welcome' | ||
} | ||
|
||
function delay() { | ||
let d = parseInt(process.env.DELAY, 10) | ||
if (isNaN(d) || d < 0) { | ||
return 0 | ||
} | ||
return d | ||
return parseInt(process.env.DELAY || '0', 10) | ||
} | ||
|
||
function port() { | ||
return process.env.PORT || 8080 | ||
} | ||
|
||
module.exports = { | ||
const config = { | ||
sink, | ||
greeting, | ||
delay | ||
greet, | ||
delay, | ||
port | ||
} | ||
|
||
const schema = Joi.object({ | ||
sink: Joi.string() | ||
.uri({ scheme: /https?/ }) | ||
.required(), | ||
|
||
greet: Joi.string() | ||
.pattern(new RegExp('^[A-Z][a-z]+$')) | ||
.required(), | ||
|
||
delay: Joi.number() | ||
.min(0) | ||
.required(), | ||
|
||
port: Joi.number() | ||
.min(0) | ||
.required() | ||
}) | ||
|
||
const { error } = schema.validate({ | ||
sink: config.sink(), | ||
greet: config.greet(), | ||
delay: config.delay(), | ||
port: config.port() | ||
}) | ||
if (error) { | ||
throw error | ||
} | ||
|
||
module.exports = config |
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
Oops, something went wrong.