-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default NODE_ENV to "development" if it's
undefined
when starting j…
…obs worker (#11572) This mimics the behavior of `yarn rw dev` where `NODE_ENV` will equal `development` if you don't set it explicitly. Because of this, you need to make sure you explicitly set it in other environments. You should set `NODE_ENV=production` in your `.env` file/Dockerfile on your production server, for example. The docs have been updated to note this. Closes #11569
- Loading branch information
Showing
8 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- Default NODE_ENV to "development" if it's `undefined` when starting jobs worker (#11572) by @cannikin | ||
|
||
This mimics the behavior of `yarn rw dev` where `NODE_ENV` will equal `development` if you don't set it explicitly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it, vi, afterEach } from 'vitest' | ||
|
||
import { setupEnv } from '../setupEnv' | ||
|
||
vi.mock('@redwoodjs/cli-helpers/loadEnvFiles', () => { | ||
return { | ||
loadEnvFiles: () => {}, | ||
} | ||
}) | ||
|
||
const ORIGNAL_NODE_ENV = process.env.NODE_ENV | ||
|
||
describe('setupEnv', () => { | ||
afterEach(() => { | ||
process.env.NODE_ENV = ORIGNAL_NODE_ENV | ||
}) | ||
|
||
it('if not called, NODE_ENV is not overridden in any way', () => { | ||
expect(process.env.NODE_ENV).toEqual(ORIGNAL_NODE_ENV) | ||
}) | ||
|
||
it('sets NODE_ENV to development if it starts undefined', () => { | ||
delete process.env.NODE_ENV | ||
|
||
setupEnv() | ||
|
||
expect(process.env.NODE_ENV).toEqual('development') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { loadEnvFiles } from '@redwoodjs/cli-helpers/loadEnvFiles' | ||
|
||
export const setupEnv = () => { | ||
loadEnvFiles() | ||
|
||
// If even after loading `.env` we find that `NODE_ENV` is `undefined` default | ||
// to `development` to mimic what the other CLI tools to | ||
if (process.env.NODE_ENV === undefined) { | ||
process.env.NODE_ENV = 'development' | ||
} | ||
} |