diff options
Diffstat (limited to '')
-rw-r--r-- | integration/apps/bun-dev-index-html.sh | 22 | ||||
-rw-r--r-- | src/http.zig | 46 |
2 files changed, 47 insertions, 21 deletions
diff --git a/integration/apps/bun-dev-index-html.sh b/integration/apps/bun-dev-index-html.sh index ed8ec5912..3277b0bcd 100644 --- a/integration/apps/bun-dev-index-html.sh +++ b/integration/apps/bun-dev-index-html.sh @@ -8,55 +8,59 @@ dir=$(mktemp -d --suffix=bun-dev-check) index_content="<html><body>index.html</body></html>" bacon_content="<html><body>bacon.html</body></html>" -js_content="if(0) { var foo = 'TEST FAILED'; } console.log(<div>123</div> && console.log('hi'))" +js_content="if(0) { var foo = 'TEST FAILED'; }" static_content="PASS" +css_not_transpiled_content="@import url(/index.js); @import url(/i-dont-exist.css); @import url('/i-dont-exist.css'); @import url(\"/i-dont-exist.css\");" +css_is_transpiled_import="*{background-color:red;}" +css_is_transpiled="@import url(./css_is_transpiled_import.css);" echo $index_content >"$dir/index.html" echo $js_content >"$dir/index.js" echo $bacon_content >"$dir/bacon.html" echo $static_content >"$dir/static.txt" +echo $css_not_transpiled_content >"$dir/css_not_transpiled_content.css" cd $dir $BUN_BIN --port 8087 & sleep 0.005 -if [ "$(curl --fail -sS http://localhost:8087/)" != "$index_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/)" != "$index_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/index)" != "$index_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/index)" != "$index_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/index)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/static.txt)" != "PASS" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/static.txt)" != "PASS" ]]; then echo "ERR: Expected static file, got '$(curl --fail -sS http://localhost:8087/static.txt)'" exit 1 fi # Check that the file is actually transpiled -if [ "$(curl --fail -sS http://localhost:8087/index.js)" != "*TEST FAILED*" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/index.js)" == *"TEST FAILED"* ]]; then echo "ERR: Expected file to be transpiled, got '$(curl --fail -sS http://localhost:8087/index.js)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/index.html)" != "$index_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/index.html)" != "$index_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/index.html)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/foo/foo)" != "$index_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/foo/foo)" != "$index_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/index.html)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/bacon)" != "$bacon_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/bacon)" != "$bacon_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/bacon)'" exit 1 fi -if [ "$(curl --fail -sS http://localhost:8087/bacon.html)" != "$bacon_content" ]; then +if [[ "$(curl --fail -sS http://localhost:8087/bacon.html)" != "$bacon_content" ]]; then echo "ERR: Expected '$index_content', got '$(curl --fail -sS http://localhost:8087/bacon.html)'" exit 1 fi diff --git a/src/http.zig b/src/http.zig index 1d08a334d..58176df6c 100644 --- a/src/http.zig +++ b/src/http.zig @@ -497,6 +497,10 @@ pub const RequestContext = struct { _path = tmp_buildfile_buf[0 .. relative_unrooted_path.len + "/index.html".len]; } + if (extensionless and !strings.eqlComptime(std.fs.path.extension(_path), ".html")) { + break; + } + if (public_dir.openFile(_path, .{})) |file| { const __path = _path; relative_unrooted_path = __path; @@ -3645,7 +3649,7 @@ pub const Server = struct { // Note: the public folder may actually just be the root folder // In this case, we only check if the pathname has no extension if (!finished) { - if (req_ctx.matchPublicFolder(comptime features.public_folder != .first)) |result| { + if (req_ctx.matchPublicFolder(comptime features.public_folder == .last or features.single_page_app_routing)) |result| { finished = true; req_ctx.renderServeResult(result) catch |err| { Output.printErrorln("FAIL [{s}] - {s}: {s}", .{ @errorName(err), req.method, req.path }); @@ -3854,18 +3858,36 @@ pub const Server = struct { }, ); } else if (server.bundler.options.routes.static_dir_enabled) { - if (!public_folder_is_top_level) { - try server.run( - ConnectionFeatures{ - .public_folder = .first, - }, - ); + if (server.bundler.options.routes.single_page_app_routing) { + if (!public_folder_is_top_level) { + try server.run( + ConnectionFeatures{ + .public_folder = .first, + .single_page_app_routing = true, + }, + ); + } else { + try server.run( + ConnectionFeatures{ + .public_folder = .last, + .single_page_app_routing = true, + }, + ); + } } else { - try server.run( - ConnectionFeatures{ - .public_folder = .last, - }, - ); + if (!public_folder_is_top_level) { + try server.run( + ConnectionFeatures{ + .public_folder = .first, + }, + ); + } else { + try server.run( + ConnectionFeatures{ + .public_folder = .last, + }, + ); + } } } else if (server.bundler.options.routes.single_page_app_routing) { try server.run( |