{"id":276,"date":"2023-12-16T11:58:31","date_gmt":"2023-12-16T15:58:31","guid":{"rendered":"https:\/\/notebook.chaopricha.com\/?p=276"},"modified":"2023-12-16T14:51:08","modified_gmt":"2023-12-16T18:51:08","slug":"how-to-make-godot-4-x-web-export-work-on-a-webserver-apache-based","status":"publish","type":"post","link":"https:\/\/notebook.chaopricha.com\/?p=276","title":{"rendered":"How To Make GoDot 4.x Web Export Work On A Hosted Web Server (Apache based)"},"content":{"rendered":"\n<p>I&#8217;m currently learning how to make games in GoDot 4.x and it&#8217;s been great so far and I even have the first tutorial game working on my PC computer.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"602\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1024x602.png\" alt=\"\" class=\"wp-image-277\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1024x602.png 1024w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-300x176.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-768x451.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-500x294.png 500w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image.png 1157w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This is great and all, but I want to share my game with other people.  The first thought is to export it to HTML5 so I can just run it on my website hosted here by ICDSoft.  My webhost is just an Apache based host running Linux of some sort.  They do provide several cool server side stuff like php, mySQL, etc.  However, the server plan I have doesn&#8217;t do node.js and things like that would allow me to run React framework.  (They do have a Web App plan that lets you do that).  Anyway, GoDot 4.x game export to HTML5 shouldn&#8217;t really need that.  Exporting my game to a runnable web format is pretty straight forward in GoDot 4.x.  Just go to Projects -&gt; Export &#8230;<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1-1024x557.png\" alt=\"\" class=\"wp-image-278\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1-1024x557.png 1024w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1-300x163.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1-768x418.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1-500x272.png 500w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-1.png 1244w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>If you haven&#8217;t chosen any export presets, just click Add&#8230; at the top and then choose Web. This will create the presets you need to export to the web.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"732\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2.png\" alt=\"\" class=\"wp-image-279\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2.png 902w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2-300x243.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2-768x623.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-2-370x300.png 370w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/a><\/figure>\n\n\n\n<p>The only thing you really need to fill out is where you want the export path to be.  I just have it export to a &#8220;Web&#8221; folder inside my project to keep things clean since several files will be generated by the export. <strong> Make sure that you toggle the Runnable to enable<\/strong> so that the game is runnable from the html file you chose.<br><br>Click Export All &#8230; to start the process.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"901\" height=\"727\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3.png\" alt=\"\" class=\"wp-image-280\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3.png 901w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3-300x242.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3-768x620.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-3-372x300.png 372w\" sizes=\"(max-width: 901px) 100vw, 901px\" \/><\/a><\/figure>\n\n\n\n<p>If you go to the export folder you chose, you&#8217;ll se a bunch of files needed for your web output to run.  Note that the html file just won&#8217;t run on your Chrome or FireFox browser locally without a webserver of some sort.  <br><br>There are many guides on how to spin up a local server to run your GoDot 4.x project like this one: <br><a href=\"https:\/\/github.com\/TechnoLukas\/Godot4-html-localy\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/TechnoLukas\/Godot4-html-localy<\/a><br><br>or a nice an simple Python3 server like this one:<br><a href=\"https:\/\/gist.github.com\/opyate\/6e5fcabc6f41474d248613c027373856\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/gist.github.com\/opyate\/6e5fcabc6f41474d248613c027373856<\/a><\/p>\n\n\n\n<p>However, I don&#8217;t need a local server running since I already have my web host.  Unfortunately, it&#8217;s actually not that simple due to this particular error when trying to run the game on my website after uploading all the exported files.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"366\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4.png\" alt=\"\" class=\"wp-image-281\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4.png 825w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4-300x133.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4-768x341.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-4-500x222.png 500w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/a><\/figure>\n\n\n\n<p>My initial thought was that maybe I can&#8217;t just run it on my web host but that&#8217;s a bit disappointing since I didn&#8217;t have problems running games made with Unity on the web.  It&#8217;s a bit disappointing.  I&#8217;m using GoDot 4.0.2 to be compatible with the tutorials I&#8217;m following.  At the time of this post, GoDot 4.2 is the latest but it sounds like this is still an issue if your web server doesn&#8217;t have Cross Origin Isolation configured.  I did a lot of web searches but there wasn&#8217;t a lot of solutions other than posting my game on <a href=\"http:\/\/itch.io\" data-type=\"link\" data-id=\"itch.io\">itch.io<\/a>.  <\/p>\n\n\n\n<p>I started reading through the GoDot help (<a href=\"https:\/\/docs.godotengine.org\/en\/stable\/tutorials\/export\/exporting_for_web.html#\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.godotengine.org\/en\/stable\/tutorials\/export\/exporting_for_web.html#<\/a>) to see whether there are anything that could help me solve this problem.  I came across this section about coi-serviceworker as a workaround.  That could be the answer!<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"375\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5.png\" alt=\"\" class=\"wp-image-282\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5.png 812w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5-300x139.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5-768x355.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-5-500x231.png 500w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/a><\/figure>\n\n\n\n<p>The link took me to a GitHub project:  https:\/\/github.com\/gzuidhof\/coi-serviceworker and the instruction is pretty clear.  <br><br><strong>You have 2 options (pick one):<\/strong><br>1) Download <a href=\"https:\/\/chaopricha.com\/misc\/coi-serviceworker.js\" data-type=\"link\" data-id=\"https:\/\/chaopricha.com\/misc\/coi-serviceworker.js\">coi-serviceworker.js<\/a> (6 kB)into your web export folder and add this line to your html file:<\/p>\n\n\n\n<p class=\"has-light-gray-background-color has-text-color has-background has-link-color wp-elements-7419d3e2896423e80df00be18b05e69a\" style=\"color:#1921d1\"><code>&lt;script src=\"coi-serviceworker.js\"&gt;&lt;\/script&gt;<\/code><\/p>\n\n\n\n<p>2) Download <a href=\"https:\/\/chaopricha.com\/misc\/coi-serviceworker.min.js\" data-type=\"link\" data-id=\"https:\/\/chaopricha.com\/misc\/coi-serviceworker.min.js\">coi-serviceworker.min.js<\/a> (3 kB) in to your export folder and add this line to your html file:<\/p>\n\n\n\n<p class=\"has-light-gray-background-color has-text-color has-background has-link-color wp-elements-40a45586b2699edda47f4937d0bacacd\" style=\"color:#1921d1\"><code>&lt;script src=\"coi-serviceworker.min.js\"&gt;&lt;\/script&gt;<\/code><\/p>\n\n\n\n<p>I tried option 2 to minimize the extra file size to include.  I edited my speedy_saucer.html file and scroll to where the &lt;script&gt; section is and add the extra tag. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"432\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6-1024x432.png\" alt=\"\" class=\"wp-image-283\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6-1024x432.png 1024w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6-300x127.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6-768x324.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6-500x211.png 500w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-6.png 1372w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>I saved the file and uploaded it along with the coi-serviceworker.min.js into my web project folder.  Now I went to my website location where I uploaded the GoDot 4.x web export folder again and it worked!!!<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7-1024x640.png\" alt=\"\" class=\"wp-image-284\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7-1024x640.png 1024w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7-300x187.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7-768x480.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7-480x300.png 480w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-7.png 1375w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Another way to include the script is to add it in the Head Include during the export.  Make sure to have the correct corresponding coi-serviceworker js  file in your project.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"731\" src=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8.png\" alt=\"\" class=\"wp-image-288\" srcset=\"https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8.png 900w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8-300x244.png 300w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8-768x624.png 768w, https:\/\/notebook.chaopricha.com\/wp-content\/uploads\/2023\/12\/image-8-369x300.png 369w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/a><\/figure>\n\n\n\n<p><br>Maybe in the future update of GoDot 4.x this problem would be solved, but in the mean time the workaronud works great.  Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m currently learning how to make games in GoDot 4.x and it&#8217;s been great so far and I even have the first tutorial game working on my PC computer. This is great and all, but I want to share my &hellip; <a href=\"https:\/\/notebook.chaopricha.com\/?p=276\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/posts\/276"}],"collection":[{"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=276"}],"version-history":[{"count":4,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":289,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions\/289"}],"wp:attachment":[{"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notebook.chaopricha.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}