Skip to content

Commit

Permalink
Merge pull request #9 from AthennaIO/develop
Browse files Browse the repository at this point in the history
refactor: get app environment from string content
  • Loading branch information
jlenon7 authored Mar 31, 2022
2 parents 7d2f170 + 8fa04a7 commit 8a81e88
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "1.0.7",
"version": "1.0.8",
"description": "",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
12 changes: 5 additions & 7 deletions src/Factories/AthennaFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* file that was distributed with this source code.
*/

import { Path } from '@secjs/utils'
import { Logger } from '@athenna/logger'
import { normalize, parse } from 'path'
import { Http, Router } from '@athenna/http'
import { resolveEnvFile } from '@athenna/config'
import { Config as SecConfig, Path } from '@secjs/utils'
import { getAppEnvironment } from 'src/Utils/getAppEnvironment'
import { ResolveClassExport } from 'src/Utils/ResolveClassExport'
import { AthennaErrorHandler } from 'src/Utils/AthennaErrorHandler'

Expand All @@ -24,14 +25,11 @@ export class AthennaFactory {

AthennaFactory.resolveNodeTs(fileName)

const secConfig = new SecConfig()

secConfig.load(Path.config(`app${AthennaFactory.extension}`))
process.env.NODE_ENV = SecConfig.get('app.environment')
process.env.NODE_ENV = getAppEnvironment(
Path.config(`app${AthennaFactory.extension}`),
)

resolveEnvFile()

secConfig.load(Path.config(`app${AthennaFactory.extension}`))
Config.load(Path.config())

AthennaFactory.logger = new Logger().channel('application', {
Expand Down
26 changes: 26 additions & 0 deletions src/Utils/getAppEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @athenna/core
*
* (c) João Lenon <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { File } from '@secjs/utils'

export function getAppEnvironment(path: string): string {
let env = new File(path)
.loadSync()
.getContentSync()
.toString()
.split('environment:')[1]
.split(',')[0]
.trim()

if (env.includes('process.env.NODE_ENV')) {
env = env.split('process.env.NODE_ENV')[1].replace('/||/g', '').trim()
}

return process.env.NODE_ENV || env
}
2 changes: 1 addition & 1 deletion tests/Unit/IgniteTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('\n IgniteTest', () => {
expect(Config.get('app.name')).toBe('Athenna')
expect(Config.get('app.domain')).toBe('http://localhost:1335')

const { json, statusCode } = await app.getServer().inject({
const { json, statusCode } = await app.request({
method: 'GET',
url: '/healthcheck',
})
Expand Down

0 comments on commit 8a81e88

Please sign in to comment.