-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup_now.js
51 lines (45 loc) · 1.59 KB
/
setup_now.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require("dotenv").config();
const crypto = require("crypto");
const { execSync } = require("child_process");
const url = require("url");
const inquirer = require("inquirer");
function addEnvVar(key, value) {
try {
execSync(`printf "${value}" | npx now env add "${key}" production`);
} catch {
console.error(
`Could not add "${key}". If it already exists, that's fine. If you want to update an existing environment variable, run "npx now env rm ${key} production"`
);
}
}
inquirer
.prompt([
{
type: "input",
name: "prodUrl",
message: "What is your app's production url?",
validate: (value) => {
const valid = /^https:\/\//.test(value);
return (
valid ||
"Invalid url. This should be the production url copied from running 'npx now'"
);
},
},
])
.then(({ prodUrl }) => {
prodUrl = prodUrl.trim();
addEnvVar("AUTH0_DOMAIN", process.env.AUTH0_DOMAIN);
addEnvVar("AUTH0_CLIENT_ID", process.env.AUTH0_CLIENT_ID);
addEnvVar("AUTH0_CLIENT_SECRET", process.env.AUTH0_CLIENT_SECRET);
addEnvVar("REDIRECT_URI", url.resolve(prodUrl, "/api/callback"));
addEnvVar("POST_LOGOUT_REDIRECT_URI", prodUrl);
// This generates a random value for SESSION_COOKIE_SECRET
// The importance of this is explained here:
// https://martinfowler.com/articles/session-secret.html
addEnvVar("SESSION_COOKIE_SECRET", crypto.randomBytes(32).toString("hex"));
console.log("Configured all environment variables. Redeploying...");
execSync("npx now --prod", {
stdio: "inherit",
});
});