Skip to content

Commit

Permalink
Merge pull request #57 from commercetools/add-possibility-to-set-keep…
Browse files Browse the repository at this point in the history
…AliveTimeout

Add possibility to set keep alive timeout
  • Loading branch information
LEQADA committed Apr 26, 2019
2 parents 32cef94 + 108837b commit 5f3b98e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions extension/docs/IntegrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ In order to make the extension module working, following parameters have to be p
| `API_EXTENSION_BASE_URL` | URL of the Extension module. This URL will be called by CTP Extension endpoint. |
| `ADYEN_API_KEY` | Go to [Account/Users](https://ca-test.adyen.com/ca/ca/config/users.shtml) - Select a user with `Web Service` User type - Generate New API Key (notice: in case you get `403 Forbidden` error from Adyen, try to regenerate the key). |
| `ADYEN_MERCHANT_ACCOUNT` | Go to [Account/Merchant accounts](https://ca-test.adyen.com/ca/ca/accounts/show.shtml?accountTypeCode=MerchantAccount) and get the name in Acccount code. | |
| `KEEP_ALIVE_TIMEOUT` | milliseconds to keep a socket alive after the last response ([Node.js docs](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_server_keepalivetimeout)) |

# Checkout steps
In your shop, ensure the steps below are done:
Expand Down
4 changes: 3 additions & 1 deletion extension/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function getEnvConfig () {
return {
port: process.env.PORT,
logLevel: process.env.LOG_LEVEL,
apiExtensionBaseUrl: process.env.API_EXTENSION_BASE_URL
apiExtensionBaseUrl: process.env.API_EXTENSION_BASE_URL,
keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10)
: undefined
}
}

Expand Down
2 changes: 2 additions & 0 deletions extension/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const { ensureResources } = require('./config/init/ensure-resources')
const port = parseInt(process.env.EXTENSION_PORT || 8080, 10)
const logger = utils.getLogger()

if (config.keepAliveTimeout !== undefined)
server.keepAliveTimeout = config.keepAliveTimeout
init.listen(port, async () => {
await ensureResources()
logger.info(`Server running at http://127.0.0.1:${port}/`)
Expand Down
1 change: 1 addition & 0 deletions notification/docs/DevelopmentGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CTP_CLIENT_ID | commercetools client ID with `manage_types` and `manage_payments
CTP_CLIENT_SECRET | commercetools client secret (you can get in the [commercetools Merchant Center](https://mc.commercetools.com)) | **YES** |
LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
PORT | port on which the application will run | NO | 443
KEEP_ALIVE_TIMEOUT | milliseconds to keep a socket alive after the last response ([Node.js docs](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_server_keepalivetimeout)) | NO | Node.js default

Don't forget to provide all required environment variables
After setting all variables, execute command `npm run start` to run the module.
Expand Down
1 change: 1 addition & 0 deletions notification/docs/IntegrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CTP_CLIENT_ID | commercetools client ID (you can get in the commercetools Mercha
CTP_CLIENT_SECRET | commercetools client secret (you can get in the commercetools Merchant Center) | **YES** |
LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
PORT | port on which the application will run | NO | 443
KEEP_ALIVE_TIMEOUT | milliseconds to keep a socket alive after the last response ([Node.js docs](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_server_keepalivetimeout)) | NO | Node.js default

Check out the deployment [Best Practices documentation](../../docs/BEST_PRACTICES.md)

Expand Down
4 changes: 3 additions & 1 deletion notification/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ let config

function getEnvConfig () {
return {
logLevel: process.env.LOG_LEVEL
logLevel: process.env.LOG_LEVEL,
keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10)
: undefined
}
}

Expand Down
2 changes: 2 additions & 0 deletions notification/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const ctpClient = ctp.get(config)

const PORT = process.env.PORT || 443

if (config.keepAliveTimeout !== undefined)
server.keepAliveTimeout = config.keepAliveTimeout
server.listen(PORT, async () => {
await ensureInterfaceInteractionCustomType(ctpClient)
logger.info(`Server started on ${PORT} port`)
Expand Down

0 comments on commit 5f3b98e

Please sign in to comment.