From 493d9123fd0baa0cfe6041dcee27a838dc8be973 Mon Sep 17 00:00:00 2001 From: Jarmo Isotalo Date: Sat, 3 Jun 2017 16:44:14 +0200 Subject: [PATCH] Option `--session-affinity` was added for setting session affinity (#600) --- bin/now-deploy.js | 21 ++++++++++++++------- lib/index.js | 6 ++++-- lib/read-metadata.js | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 08fd659..c5b363c 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -38,7 +38,7 @@ const promptOptions = require('../lib/utils/input/prompt-options') const note = require('../lib/utils/output/note') const argv = minimist(process.argv.slice(2), { - string: ['config', 'token', 'name', 'alias'], + string: ['config', 'token', 'name', 'alias', 'session-affinity'], boolean: [ 'help', 'version', @@ -67,6 +67,7 @@ const argv = minimist(process.argv.slice(2), { public: 'p', 'no-clipboard': 'C', 'forward-npm': 'N', + 'session-affinity': 'S', name: 'n', alias: 'a' } @@ -117,6 +118,7 @@ const help = () => { -E ${chalk.underline('FILE')}, --dotenv=${chalk.underline('FILE')} Include env vars from .env file. Defaults to '.env' -C, --no-clipboard Do not attempt to copy URL to clipboard -N, --forward-npm Forward login information to install private npm modules + --session-affinity Session affinity, \`ip\` (default) or \`random\` to control session affinity. ${chalk.dim('Enforcable Types (when both package.json and Dockerfile exist):')} @@ -168,6 +170,7 @@ const gitRepo = {} // Options let forceNew = argv.force let deploymentName = argv.name +let sessionAffinity = argv['session-affinity'] const debug = argv.debug const clipboard = !argv['no-clipboard'] const forwardNpm = argv['forward-npm'] @@ -349,10 +352,11 @@ async function sync({ token, config: { currentTeam, user } }) { } let meta - ;({ meta, deploymentName, deploymentType } = await readMeta( + ;({ meta, deploymentName, deploymentType, sessionAffinity } = await readMeta( path, deploymentName, - deploymentType + deploymentType, + sessionAffinity )) const nowConfig = meta.nowConfig @@ -489,7 +493,8 @@ async function sync({ token, config: { currentTeam, user } }) { forceSync, forwardNpm: alwaysForwardNpm || forwardNpm, quiet, - wantsPublic + wantsPublic, + sessionAffinity }, meta ) @@ -633,12 +638,13 @@ async function sync({ token, config: { currentTeam, user } }) { } } -async function readMeta(path, deploymentName, deploymentType) { +async function readMeta(path, deploymentName, deploymentType, sessionAffinity) { try { const meta = await readMetaData(path, { deploymentType, deploymentName, - quiet: true + quiet: true, + sessionAffinity }) if (!deploymentType) { @@ -664,7 +670,8 @@ async function readMeta(path, deploymentName, deploymentType) { return { meta, deploymentName, - deploymentType + deploymentType, + sessionAffinity } } catch (err) { if (isTTY && err.code === 'MULTIPLE_MANIFESTS') { diff --git a/lib/index.js b/lib/index.js index 8fdea4e..5d95346 100644 --- a/lib/index.js +++ b/lib/index.js @@ -61,7 +61,8 @@ module.exports = class Now extends EventEmitter { type = 'npm', pkg = {}, nowConfig = {}, - hasNowJson = false + hasNowJson = false, + sessionAffinity = 'ip' } ) { this._path = path @@ -166,7 +167,8 @@ module.exports = class Now extends EventEmitter { deploymentType: type, registryAuthToken: authToken, files, - engines + engines, + sessionAffinity } }) diff --git a/lib/read-metadata.js b/lib/read-metadata.js index b1fc808..261399a 100644 --- a/lib/read-metadata.js +++ b/lib/read-metadata.js @@ -11,11 +11,18 @@ module.exports = readMetaData async function readMetaData( path, - { deploymentType, deploymentName, quiet = false, strict = true } + { + deploymentType, + deploymentName, + sessionAffinity, + quiet = false, + strict = true + } ) { let description let type = deploymentType let name = deploymentName + let affinity = sessionAffinity const pkg = await readJSON(path, 'package.json') let nowConfig = await readJSON(path, 'now.json') @@ -72,6 +79,10 @@ async function readMetaData( name = nowConfig.name } + if (!affinity && nowConfig) { + affinity = nowConfig.sessionAffinity + } + if (type === 'npm') { if (pkg) { if (!name && pkg.now && pkg.now.name) { @@ -152,7 +163,8 @@ async function readMetaData( hasNowJson, // XXX: legacy - deploymentType: type + deploymentType: type, + sessionAffinity: affinity } }