Skip to content

Commit

Permalink
Only create .env in developnent
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Jul 19, 2022
1 parent cbcbb6c commit d37de1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ processes = []
builder = "heroku/buildpacks:20"

[build.args]
ENV = 'production'
NODE_ENV = 'production'
DOMAIN = 'breadcrum.net'
TRANSPORT='https'
Expand Down
37 changes: 21 additions & 16 deletions scripts/generate-default-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@ const __dirname = desm(import.meta.url)
// This script sets up a default .env dotenv file for use in development
// Do not run this in production or when deploying.

const varsNeedingDevKeys = [
'COOKIE_SECRET',
'JWT_SECRET'
]
if (process.env.ENV !== 'production') {
const varsNeedingDevKeys = [
'COOKIE_SECRET',
'JWT_SECRET'
]

const dotenv = []
const dotenv = []

for (const envVar of varsNeedingDevKeys) {
const buf = Buffer.allocUnsafe(sodium.crypto_secretbox_KEYBYTES)
sodium.randombytes_buf(buf)
const hexString = buf.toString('hex')
dotenv.push(`${envVar}=${hexString}`)
}
for (const envVar of varsNeedingDevKeys) {
const buf = Buffer.allocUnsafe(sodium.crypto_secretbox_KEYBYTES)
sodium.randombytes_buf(buf)
const hexString = buf.toString('hex')
dotenv.push(`${envVar}=${hexString}`)
}

for (const [name, opts] of Object.entries(schema.properties)) {
if (opts.default) dotenv.push(`${name}=${opts.default}`)
}
for (const [name, opts] of Object.entries(schema.properties)) {
if (opts.default) dotenv.push(`${name}=${opts.default}`)
}

dotenv.push('')
await writeFile(resolve(__dirname, '../.env'), dotenv.join('\n'))
dotenv.push('')
await writeFile(resolve(__dirname, '../.env'), dotenv.join('\n'))
console.log('wrote development .env file')
} else {
console.log('skipping creation of development .env file')
}

0 comments on commit d37de1e

Please sign in to comment.