@@ -53,6 +53,7 @@ Http_server::mime_type(beast::string_view path)
5353 if (iequals (ext, " .json" )) return " application/json" ;
5454 if (iequals (ext, " .xml" )) return " application/xml" ;
5555 if (iequals (ext, " .swf" )) return " application/x-shockwave-flash" ;
56+ if (iequals (ext, " .wasm" )) return " application/wasm" ;
5657 if (iequals (ext, " .flv" )) return " video/x-flv" ;
5758 if (iequals (ext, " .png" )) return " image/png" ;
5859 if (iequals (ext, " .jpe" )) return " image/jpeg" ;
@@ -129,7 +130,7 @@ Http_server::handle_request(
129130 res.set (http::field::server, BOOST_BEAST_VERSION_STRING );
130131 res.set (http::field::content_type, " text/html" );
131132 res.keep_alive (req.keep_alive ());
132- res.body () = " The resource '" + std::string (target) + " ' was not found.y <br> Go to the following address : http://ip_address:port/remote .html." ;
133+ res.body () = " The resource '" + std::string (target) + " ' was not found.<br> Go to the following address : http://ip_address:port/ossia_remote .html." ;
133134 res.prepare_payload ();
134135 return res;
135136 };
@@ -180,20 +181,6 @@ Http_server::handle_request(
180181 // Cache the size since we need it after the move
181182 auto const size = body.size ();
182183
183- if ( req.target ().find (" ossia_remote.html" ) != std::string::npos )
184- {
185- // Load file
186- QFile f (path.c_str ());
187- f.open (QIODevice::ReadOnly);
188- QByteArray remote = f.readAll ();
189-
190- // Write ip address in the std::string
191- std::string string_remote = remote.toStdString ();
192- std::string::size_type position = string_remote.find (" %SCORE_IP_ADDRESS%" );
193- std::string addr = " \" " + m_ipAddress + " \" " ;
194- string_remote = string_remote.replace (position, 18 , addr);
195- }
196-
197184 // Respond to HEAD request
198185 if (req.method () == http::verb::head)
199186 {
@@ -210,6 +197,12 @@ Http_server::handle_request(
210197 std::piecewise_construct,
211198 std::make_tuple (std::move (body)),
212199 std::make_tuple (http::status::ok, req.version ())};
200+
201+ // Allow Cross-Origin Resource Sharing (CORS).
202+ res.set (http::field::access_control_allow_headers, " *" );
203+ res.set (http::field::access_control_allow_origin, " *" );
204+ res.set (http::field::access_control_allow_methods, " GET" );
205+
213206 res.set (http::field::server, BOOST_BEAST_VERSION_STRING );
214207 res.set (http::field::content_type, mime_type (path));
215208 res.content_length (size);
@@ -343,7 +336,7 @@ Http_server::open_server()
343336 }
344337 catch (const std::exception& e)
345338 {
346- std::cerr << " Error: " << e.what () << std::endl ;
339+ std::cerr << " Error: " << e.what () << ' \n ' ;
347340 return EXIT_FAILURE ;
348341 }
349342}
0 commit comments