Skip to content

Commit

Permalink
feat(cli): Add custom environment variable support to generated appli…
Browse files Browse the repository at this point in the history
…cation (#2751)
  • Loading branch information
daffl authored Sep 15, 2022
1 parent 21d6aaa commit c7bf80d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
9 changes: 9 additions & 0 deletions packages/cli/src/app/templates/config.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const defaultConfig = ({}: AppGeneratorContext) => ({
}
})

const customEnvironment = {
port: {
__name: 'PORT',
__format: 'number'
},
host: 'HOSTNAME'
}

const testConfig = {
port: 8998
}
Expand All @@ -20,3 +28,4 @@ export const generate = (ctx: AppGeneratorContext) =>
generator(ctx)
.then(writeJSON(defaultConfig, toFile('config', 'default.json')))
.then(writeJSON(testConfig, toFile('config', 'test.json')))
.then(writeJSON(customEnvironment, toFile('config', 'custom-environment-variables.json')))
79 changes: 45 additions & 34 deletions packages/cli/src/authentication/templates/config.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,55 @@ import { generator, toFile, mergeJSON } from '@feathershq/pinion'
import { AuthenticationGeneratorContext } from '../index'

export const generate = (ctx: AuthenticationGeneratorContext) =>
generator(ctx).then(
mergeJSON<AuthenticationGeneratorContext>(({ authStrategies }) => {
const authentication: any = {
entity: ctx.entity,
service: ctx.service,
secret: crypto.randomBytes(24).toString('base64'),
authStrategies: ['jwt'],
jwtOptions: {
header: {
typ: 'access'
},
audience: 'https://yourdomain.com',
algorithm: 'HS256',
expiresIn: '1d'
generator(ctx)
.then(
mergeJSON<AuthenticationGeneratorContext>(({ authStrategies }) => {
const authentication: any = {
entity: ctx.entity,
service: ctx.service,
secret: crypto.randomBytes(24).toString('base64'),
authStrategies: ['jwt'],
jwtOptions: {
header: {
typ: 'access'
},
audience: 'https://yourdomain.com',
algorithm: 'HS256',
expiresIn: '1d'
}
}
}

if (authStrategies.includes('local')) {
authentication.authStrategies.push('local')
authentication.local = {
usernameField: 'email',
passwordField: 'password'
if (authStrategies.includes('local')) {
authentication.authStrategies.push('local')
authentication.local = {
usernameField: 'email',
passwordField: 'password'
}
}
}

const oauthStrategies = authStrategies.filter((name) => name !== 'local')
const oauthStrategies = authStrategies.filter((name) => name !== 'local')

if (oauthStrategies.length) {
authentication.oauth = oauthStrategies.reduce((oauth, name) => {
oauth[name] = {
key: '<Client ID>',
secret: '<Client secret>'
}
if (oauthStrategies.length) {
authentication.oauth = oauthStrategies.reduce((oauth, name) => {
oauth[name] = {
key: '<Client ID>',
secret: '<Client secret>'
}

return oauth
}, {} as any)
}
return oauth
}, {} as any)
}

return { authentication }
}, toFile('config', 'default.json'))
)
return { authentication }
}, toFile('config', 'default.json'))
)
.then(
mergeJSON<AuthenticationGeneratorContext>(
{
authentication: {
secret: 'FEATHERS_SECRET'
}
},
toFile('config', 'custom-environment-variables.json')
)
)

0 comments on commit c7bf80d

Please sign in to comment.