Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add custom environment variable support to generated application #2751

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
)
)