diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..07627f2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[**.html] +indent_style = tab +tab_width = 4 + +[**.md] +trim_trailing_whitespace = false diff --git a/README.md b/README.md index f6e7af0..cceaff8 100644 --- a/README.md +++ b/README.md @@ -1,28 +1 @@ # HTML5 Gamepad Test - -Mostly because I didn't trust others ;) - -https://greggman.github.io/html5-gamepad-test/ - -## Licence: MIT - -Copyright 2019 Gregg Tavares - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - diff --git a/app.js b/app.js new file mode 100644 index 0000000..8e91091 --- /dev/null +++ b/app.js @@ -0,0 +1,45 @@ +// app.js +const http = require("http"); +const fs = require("fs"); +const path = require("path"); +const url = require("url"); + +const port = 8080; +const host = "0.0.0.0"; +const mimeTypes = { + ".html": "text/html", + ".css": "text/css", + ".js": "application/javascript", + ".svg": "image/svg+xml", + ".png": "image/png", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".gif": "image/gif", + ".ico": "image/x-icon", + ".json": "application/json", + ".txt": "text/plain", +}; + +http + .createServer((req, res) => { + // Parse the URL and extract just the pathname, ignoring query parameters + const parsedUrl = url.parse(req.url); + let filePath = "." + decodeURIComponent(parsedUrl.pathname); + if (filePath === "./") filePath = "./index.html"; + + const ext = path.extname(filePath).toLowerCase(); + const contentType = mimeTypes[ext] || "application/octet-stream"; + + fs.readFile(filePath, (err, content) => { + if (err) { + res.writeHead(404); + res.end("404 Not Found"); + } else { + res.writeHead(200, { "Content-Type": contentType }); + res.end(content); + } + }); + }) + .listen(port, host, () => { + console.log(`Server running at http://${host}:${port}/`); + }); diff --git a/index.html b/index.html index 5a05397..cd6b48e 100644 --- a/index.html +++ b/index.html @@ -22,89 +22,88 @@ */ --> - -

HTML5 Gamepad Test

-
running:
-
+

HTML5 Gamepad Test

+
running:
+