diff --git a/api.js b/api.js new file mode 100644 index 0000000..f773aab --- /dev/null +++ b/api.js @@ -0,0 +1,5 @@ +const app = require("./exposer.js").app + +app.get("/*", (req, res) => { + res.send("

Sorry! Blog is undergoing large changes. Check back later!

Like... alot later.") +}) \ No newline at end of file diff --git a/exposer.js b/exposer.js new file mode 100644 index 0000000..3f7ebb2 --- /dev/null +++ b/exposer.js @@ -0,0 +1,52 @@ +const express = require("express"), +paths = require("./fileManager.js") +path = require("path"), +fs = require("fs"), +WebSocket = require("ws") + +const PORT = process.env.PORT || 8080 + +var app = express() + +app.use(express.static(paths.data)) + +app.listen(PORT, () => { + console.log("Violet's Limbo is now listening on port: " + PORT) +}) + +var sockets = [] + +wsServer = WebSocket.Server; +let server = require('http').createServer() +wsServer = new wsServer({ + server: server, + perMessageDeflate: false +}) +server.on('request', app) + +wsServer.on("connection", function connection(socket) { + socket.on('message', function message(data) { + data = JSON.parse(data) + if (data.type == "ping") { + for (let index = 0; index < sockets.length; index++) { + const socketData = sockets[index]; + if (socketData.socket == socket) { + sockets[index].lastPing = Date.now() + } + } + + socket.send(`{"op": 3}`) + } else { + console.log(data) + } + }) + + sockets.push({ socket, lastPing: Date.now() }) +}) + + +module.exports = { + app: app +} + +require("./api.js") \ No newline at end of file diff --git a/expressHandler.js b/expressHandler.js deleted file mode 100644 index 741d4f5..0000000 --- a/expressHandler.js +++ /dev/null @@ -1,23 +0,0 @@ -const express = require("express"), -paths = require("./fileManager.js"), -pageUpdater = require("./pageUpdater.js"), -path = require("path"), -fs = require("fs") - -const PORT = process.env.PORT || 8080 - -var app = express() - -app.use(express.static(paths.static)) - -app.get("/", (req, res) => { - res.send(pageUpdater.root()) -}) - -app.get('/post/:post*', (req, res) => { - res.send(pageUpdater.blogPost(req)) -}) - -app.listen(PORT, () => { - console.log("Violet's Limbo is now listening on port: " + PORT) -}) \ No newline at end of file diff --git a/index.js b/index.js index ec50904..18d42bd 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const express = require("express"), fs = require("fs"), path = require("path") -require("./expressHandler.js") +require("./exposer.js") process.on('uncaughtException', (err, origin) => { fs.writeSync( diff --git a/package-lock.json b/package-lock.json index b480755..c981df9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "dependencies": { "chokidar": "^3.5.3", "express": "^4.18.2", - "showdown": "^2.1.0" + "showdown": "^2.1.0", + "ws": "^8.18.0" } }, "node_modules/accepts": { @@ -848,6 +849,27 @@ "engines": { "node": ">= 0.8" } + }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } } } } diff --git a/package.json b/package.json index 4bfe6b8..2b4bb12 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dependencies": { "chokidar": "^3.5.3", "express": "^4.18.2", - "showdown": "^2.1.0" + "showdown": "^2.1.0", + "ws": "^8.18.0" } } diff --git a/pageUpdater.js b/pageUpdater.js deleted file mode 100644 index 71a7b35..0000000 --- a/pageUpdater.js +++ /dev/null @@ -1,66 +0,0 @@ -const fs = require("fs"), -path = require("path"), -showdown = require("showdown"), -paths = require("./fileManager.js"), -mkthtml = new showdown.Converter() - -mkthtml.setFlavor("github") - -module.exports = { - root: () => { - var data = JSON.parse(fs.readFileSync(path.join(paths.data, 'data.json'))) - var postsArray = data.posts - - var html = "" - - for (var i = 0; i < postsArray.length; i++) { - var addedHTML = "" - var post = postsArray[i] - - - addedHTML += - `

- -

${post.name}

-

${post.desc}

-

Path: /post/${post.path}

-
-
` - - html += addedHTML - } - - html = fs.readFileSync(path.join(__dirname, 'resources/mainPage.html')).toString().replace('{POSTS}', html) - - return html - }, - blogPost: (req) => { - var postName = req.params.post - - var data = JSON.parse(fs.readFileSync(path.join(paths.data, 'data.json'))) - var postsArray = data.posts - - for (let index = 0; index < postsArray.length; index++) { - const post = postsArray[index]; - - if (post.path == postName) { - postContent = mkthtml.makeHtml(fs.readFileSync(path.join(paths.posts, post.path)).toString()) - - var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() - - html = html.replace('{POST}', postContent) - html = html.replace('{POST_TITLE}', post.name) - - // res.send(html) - return html - } - } - - var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString() - html = html.replace("{POST_TITLE}", "Not found!") - html = html.replace("{POST}", "

Couldn't find this post... Maybe try clearing your cache? Violet's Limbo is currently going through alot of backend changes, so expect things to break!

") - // res.send(html) - - return html - } -} \ No newline at end of file diff --git a/resources/mainPage.html b/resources/mainPage.html deleted file mode 100644 index b5fa166..0000000 --- a/resources/mainPage.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - Violet's Limbo - - - - - -

Home

-

Violet's Limbo

-
-

Violet's Limbo is... my blog! I talk about game design, development, and whatever else comes to mind!

-

Enjoy my bad opinions!


-

Posts:

- {POSTS} -
- - \ No newline at end of file diff --git a/resources/postPage.html b/resources/postPage.html deleted file mode 100644 index 61845d7..0000000 --- a/resources/postPage.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - Violet's Limbo - - - - -

Home

-

{POST_TITLE}

-
-
- {POST} -
- - \ No newline at end of file diff --git a/static/fonts/encode-sans-expanded-v11-latin-regular.woff2 b/static/fonts/encode-sans-expanded-v11-latin-regular.woff2 deleted file mode 100644 index dbdfceb..0000000 Binary files a/static/fonts/encode-sans-expanded-v11-latin-regular.woff2 and /dev/null differ diff --git a/static/fonts/rubik-v28-latin-regular.woff2 b/static/fonts/rubik-v28-latin-regular.woff2 deleted file mode 100644 index ac6ff68..0000000 Binary files a/static/fonts/rubik-v28-latin-regular.woff2 and /dev/null differ diff --git a/static/fonts/source-code-pro-v23-latin-regular.woff2 b/static/fonts/source-code-pro-v23-latin-regular.woff2 deleted file mode 100644 index b62bc79..0000000 Binary files a/static/fonts/source-code-pro-v23-latin-regular.woff2 and /dev/null differ diff --git a/static/style.css b/static/style.css deleted file mode 100644 index f6f7c4b..0000000 --- a/static/style.css +++ /dev/null @@ -1,124 +0,0 @@ -@font-face { - font-display: swap; - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 400; - src: url('../fonts/source-code-pro-v23-latin-regular.woff2') format('woff2'); -} - -@font-face { - font-display: swap; - font-family: 'Rubik'; - font-style: normal; - font-weight: 400; - src: url('../fonts/rubik-v28-latin-regular.woff2') format('woff2'); -} - -@font-face { - font-display: swap; - font-family: 'Encode Sans Expanded'; - font-style: normal; - font-weight: 400; - src: url('../fonts/encode-sans-expanded-v11-latin-regular.woff2') format('woff2'); -} - -* { - font-family: "Encode Sans Expanded", "Rubik", Verdana, Geneva, Tahoma, sans-serif; - padding: 0; - /* text-align: center; */ -} - -h1 { - color: rgb(0, 255, 0); - font-size: 2.5rem; - text-align: center; -} - -h2 { - color: rgb(0, 255, 0); -} - -li, -h3, h4, h5, h6 { - color: white; -} - -h3 { - font-size: 1.5rem; -} - -body, -html { - margin: auto; - background-color: rgb(10, 10, 10); - margin: 0; - padding: 0; -} - -body { - padding: 2.5%; -} - -main { - margin: auto; - max-width: 1000px; -} - -a { - color: rgb(175, 225, 255); - display: inline-block; - transition: 1.5s all cubic-bezier(0.075, 0.82, 0.165, 1); -} - -.textBlock { - color: rgb(255, 255, 255); - white-space: pre-wrap; - background-color: rgb(20, 20, 20); - border: 2px lightgray solid; - padding: 0 10px; - font-style: italic; - font-family: 'Source Code Pro', sans-serif; - text-align: center; -} - -.post { - color: rgb(240, 240, 240); - background-color: rgb(5, 5, 5); - border: 2px gray solid; - padding: 10px; - padding-top: 0; - margin: 25px 10px; - text-align: center; -} - -a:hover { - color: white; - transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1); -} - -p, li { - color: white; - font-size: 1.2rem; - padding: 0; - margin: 10px; - line-height: 2rem; -} - -img { - width: 100%; - max-width: 135px; - transition: all 2s cubic-bezier(0.075, 0.82, 0.165, 1); -} - -hr { - color: white; - opacity: 0.25; - border-width: 2px; - margin: 15px 10%; -} - -ol, ul { - display: block; - width: 80%; - margin: auto; -} \ No newline at end of file