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

fix: uncomment NEXT_PUBLIC_URL and NODE_TLS_REJECT_UNAUTHORIZED in the generated .env #73

Merged
merged 7 commits into from
Feb 13, 2025
4 changes: 2 additions & 2 deletions access-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function snapwp_helper_get_env_variables() {
$upload_path = '/' . ltrim( str_replace( ABSPATH, '', $upload_dir['basedir'] ), '/' );

return [
'NODE_TLS_REJECT_UNAUTHORIZED' => '',
'NEXT_PUBLIC_URL' => '',
'NODE_TLS_REJECT_UNAUTHORIZED' => '0',
'NEXT_PUBLIC_URL' => 'http://localhost:3000',
'NEXT_PUBLIC_WORDPRESS_URL' => untrailingslashit( get_home_url() ),
'NEXT_PUBLIC_GRAPHQL_ENDPOINT' => graphql_get_endpoint(),
'NEXT_PUBLIC_WORDPRESS_UPLOADS_PATH' => $upload_path,
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/EnvGenerator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function prepare_variable( string $name, ?string $value ): ?string {
$required = ! empty( $variable['required'] );

// Check if a required variable has a value.
justlevine marked this conversation as resolved.
Show resolved Hide resolved
if ( $required && empty( $value ) ) {
if ( $required && empty( $value ) && '0' !== $value ) {
throw new \InvalidArgumentException( 'Required variables must have a value.' );
}

Expand Down
4 changes: 2 additions & 2 deletions src/Modules/EnvGenerator/VariableRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class VariableRegistry {
'NODE_TLS_REJECT_UNAUTHORIZED' => [
'description' => 'Enable if connecting to a self-signed cert',
justlevine marked this conversation as resolved.
Show resolved Hide resolved
'default' => '0',
'required' => false,
'required' => true,
],
'NEXT_PUBLIC_URL' => [
'description' => 'The headless frontend domain URL. Uncomment this line and ensure the value matches the URL used by your frontend app.',
justlevine marked this conversation as resolved.
Show resolved Hide resolved
'default' => 'http://localhost:3000',
'required' => false,
'required' => true,
],
'NEXT_PUBLIC_WORDPRESS_URL' => [
'description' => 'The WordPress "frontend" domain URL',
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGenerateEnvContent(): void {
NODE_TLS_REJECT_UNAUTHORIZED=5

# The headless frontend domain URL. Uncomment this line and ensure the value matches the URL used by your frontend app.
# NEXT_PUBLIC_URL=http://localhost:3000
NEXT_PUBLIC_URL=http://localhost:3000

# The WordPress "frontend" domain URL
NEXT_PUBLIC_WORDPRESS_URL=https://headless-demo.local
Expand Down Expand Up @@ -111,8 +111,8 @@ public function testDefaultValuesForEnvContent(): void {

// CASE : For NODE_TLS_REJECT_UNAUTHORIZED with no default value, Generator class should comment out the variable in .ENV content.
$values = [
'NODE_TLS_REJECT_UNAUTHORIZED' => '',
'NEXT_PUBLIC_URL' => '',
'NODE_TLS_REJECT_UNAUTHORIZED' => '0',
'NEXT_PUBLIC_URL' => 'http://localhost:3000',
'NEXT_PUBLIC_WORDPRESS_URL' => 'https://headless-demo.local',
'NEXT_PUBLIC_GRAPHQL_ENDPOINT' => '/test_endpoint',
'NEXT_PUBLIC_WORDPRESS_UPLOADS_PATH' => '',
Expand All @@ -127,10 +127,10 @@ public function testDefaultValuesForEnvContent(): void {
// Define expected content.
$expectedContent = '
# Enable if connecting to a self-signed cert
# NODE_TLS_REJECT_UNAUTHORIZED=0
NODE_TLS_REJECT_UNAUTHORIZED=0

# The headless frontend domain URL. Uncomment this line and ensure the value matches the URL used by your frontend app.
# NEXT_PUBLIC_URL=http://localhost:3000
NEXT_PUBLIC_URL=http://localhost:3000

# The WordPress "frontend" domain URL
NEXT_PUBLIC_WORDPRESS_URL=https://headless-demo.local
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testGenerateEnvEndpoint(): void {
$this->assertNotEmpty( $actual_data['content'] );
$search = '\n';
$replace = '';
$expected = "\n# Enable if connecting to a self-signed cert\n# NODE_TLS_REJECT_UNAUTHORIZED=0\n\n# The headless frontend domain URL. Uncomment this line and ensure the value matches the URL used by your frontend app.\n# NEXT_PUBLIC_URL=http://localhost:3000\n\n# The WordPress \"frontend\" domain URL\nNEXT_PUBLIC_WORDPRESS_URL=" . get_home_url() . "\n\n# The WordPress GraphQL endpoint\nNEXT_PUBLIC_GRAPHQL_ENDPOINT=" . graphql_get_endpoint() . "\n\n# The WordPress Uploads directory path\n# NEXT_PUBLIC_WORDPRESS_UPLOADS_PATH=/" . str_replace( ABSPATH, '', wp_get_upload_dir()['basedir'] ) . "\n\n# The WordPress REST URL Prefix\n# NEXT_PUBLIC_WORDPRESS_REST_URL_PREFIX=/" . rest_get_url_prefix() . "\n\n# Token used for authenticating GraphQL introspection queries\nINTROSPECTION_TOKEN=" . IntrospectionToken::get_token();
$expected = "\n# Enable if connecting to a self-signed cert\nNODE_TLS_REJECT_UNAUTHORIZED=0\n\n# The headless frontend domain URL. Uncomment this line and ensure the value matches the URL used by your frontend app.\nNEXT_PUBLIC_URL=http://localhost:3000\n\n# The WordPress \"frontend\" domain URL\nNEXT_PUBLIC_WORDPRESS_URL=" . get_home_url() . "\n\n# The WordPress GraphQL endpoint\nNEXT_PUBLIC_GRAPHQL_ENDPOINT=" . graphql_get_endpoint() . "\n\n# The WordPress Uploads directory path\n# NEXT_PUBLIC_WORDPRESS_UPLOADS_PATH=/" . str_replace( ABSPATH, '', wp_get_upload_dir()['basedir'] ) . "\n\n# The WordPress REST URL Prefix\n# NEXT_PUBLIC_WORDPRESS_REST_URL_PREFIX=/" . rest_get_url_prefix() . "\n\n# Token used for authenticating GraphQL introspection queries\nINTROSPECTION_TOKEN=" . IntrospectionToken::get_token();

$this->assertEquals( $expected, str_replace( $search, $replace, $actual_data['content'] ) );

Expand Down
Loading