Skip to content

Commit ca666ab

Browse files
authored
Add output_server_strict config (#163)
Set `output_server_strict` to true to raise a 404 for missing files when running `bin/dev` after `perron:build`. This change prevents fallback to Rails server/render, avoiding confusion with incorrectly rendered pages. Consider making this the default setting.
1 parent 65dda12 commit ca666ab

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/perron/configuration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def initialize
1515

1616
@config.output = "output"
1717

18+
@config.output_server_strict = false
19+
1820
@config.mode = :standalone
1921

2022
@config.live_reload = false

lib/perron/output_server.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def initialize(app)
88

99
def call(environment)
1010
return @app.call(environment) if disabled?
11+
return not_found if !static_file(environment) && Perron.configuration.output_server_strict
1112

1213
static_file(environment).then do |file|
1314
file ? serve(file) : @app.call(environment)
@@ -41,6 +42,14 @@ def serve(file_path)
4142
]
4243
end
4344

45+
def not_found
46+
[
47+
404,
48+
{"Content-Type" => "text/plain"},
49+
["Not Found"]
50+
]
51+
end
52+
4453
def enabled? = Dir.exist?(output_path)
4554

4655
def inject_preview_indicator(content)

0 commit comments

Comments
 (0)