Skip to content

Commit 68092cf

Browse files
committed
Move SSR server bundle to private directory
- Configure webpack to output server bundle to app/assets/builds/ - Update React on Rails config to load server bundle from private location - Add private directories to .gitignore to keep server bundles private This follows React on Rails best practices by keeping server-side rendering bundles in a private directory separate from public client assets for security.
1 parent 84f3d24 commit 68092cf

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ lib/bs
5252
/lib/ocaml
5353

5454
client/app/bundles/comments/rescript/**/*.bs.js
55+
56+
# Server-side rendering bundles (private)
57+
app/assets/builds/
58+
59+
# Generated files
60+
client/app/generated/
61+
ssr-generated/

config/initializers/react_on_rails.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# If you are never using server rendering, you may set this to "".
1313
# If you are using the same file for client and server rendering, having this set probably does
1414
# not affect performance.
15-
config.server_bundle_js_file = "server-bundle.js"
15+
# Server bundle is now in a private directory (not in public/)
16+
config.server_bundle_js_file = Rails.root.join("app", "assets", "builds", "server-bundle.js").to_s
1617

1718
# React on Rails 16 compatibility: Workaround for removed error handling
1819
#

config/webpack/serverWebpackConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ const configureServer = () => {
4545

4646
// Custom output for the server-bundle that matches the config in
4747
// config/initializers/react_on_rails.rb
48+
// Output to a private directory for SSR bundles (not in public/)
49+
const path = require('path');
4850
serverWebpackConfig.output = {
4951
filename: 'server-bundle.js',
5052
globalObject: 'this',
5153
// If using the React on Rails Pro node server renderer, uncomment the next line
5254
// libraryTarget: 'commonjs2',
53-
path: config.outputPath,
55+
path: path.resolve(__dirname, '../../app/assets/builds'),
5456
publicPath: config.publicPath,
5557
// https://webpack.js.org/configuration/output/#outputglobalobject
5658
};

0 commit comments

Comments
 (0)