Skip to content

Commit aa029fa

Browse files
Add license validation on startup for both Rails and Node renderer
1 parent e2af939 commit aa029fa

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

react_on_rails_pro/lib/react_on_rails_pro/engine.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,28 @@ class Engine < Rails::Engine
77
initializer "react_on_rails_pro.routes" do
88
ActionDispatch::Routing::Mapper.include ReactOnRailsPro::Routes
99
end
10+
11+
# Validate license on Rails startup
12+
# This ensures the application fails fast if the license is invalid or missing
13+
initializer "react_on_rails_pro.validate_license", before: :load_config_initializers do
14+
config.after_initialize do
15+
# Skip license validation during asset precompilation
16+
next if defined?(Rake) && Rake::Task.task_defined?("assets:precompile")
17+
18+
# Skip license validation when running RSpec tests
19+
# Tests mock the license validation with stub keys
20+
next if defined?(RSpec)
21+
22+
Rails.logger.info "[React on Rails Pro] Validating license..."
23+
24+
if ReactOnRailsPro::LicenseValidator.valid?
25+
Rails.logger.info "[React on Rails Pro] License validation successful"
26+
else
27+
# License validation will raise an error, so this line won't be reached
28+
# But we include it for clarity
29+
Rails.logger.error "[React on Rails Pro] License validation failed"
30+
end
31+
end
32+
end
1033
end
1134
end

react_on_rails_pro/packages/node-renderer/src/master.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ import { isLicenseValid, getLicenseValidationError } from './shared/licenseValid
1212
const MILLISECONDS_IN_MINUTE = 60000;
1313

1414
export = function masterRun(runningConfig?: Partial<Config>) {
15-
// Validate license before starting
15+
// Validate license before starting - required in all environments
16+
log.info('[React on Rails Pro] Validating license...');
17+
1618
if (!isLicenseValid()) {
1719
const error = getLicenseValidationError() || 'Invalid license';
18-
const isDevelopment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
19-
20-
if (isDevelopment) {
21-
log.warn(`[React on Rails Pro] ${error}`);
22-
// Continue in development with warning
23-
} else {
24-
log.error(`[React on Rails Pro] ${error}`);
25-
process.exit(1);
26-
}
27-
} else {
28-
log.info('[React on Rails Pro] License validation successful');
20+
log.error(`[React on Rails Pro] ${error}`);
21+
// License validation already calls process.exit(1) in handleInvalidLicense
22+
// But we add this for safety in case the validator changes
23+
process.exit(1);
2924
}
3025

26+
log.info('[React on Rails Pro] License validation successful');
27+
3128
// Store config in app state. From now it can be loaded by any module using getConfig():
3229
const config = buildConfig(runningConfig);
3330
const { workersCount, allWorkersRestartInterval, delayBetweenIndividualWorkerRestarts } = config;

0 commit comments

Comments
 (0)