From 1e850048bd1588b836dac8665370929ee450ae6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Thu, 17 Jan 2019 14:41:26 -0600 Subject: [PATCH] Closes #207 and reformats some things --- app/dist/scripts/api.js | 2 +- app/dist/scripts/app.js | 14 +----- app/dist/scripts/plugins/jets.js | 2 +- app/dist/scripts/sockets.js | 2 +- app/index.js | 85 ++++++++++++++++++++++++++++++- app/sass/_layout.scss | 58 --------------------- index.js | 14 ++++++ package.json | 8 +-- server.js | 86 -------------------------------- 9 files changed, 105 insertions(+), 166 deletions(-) create mode 100755 index.js delete mode 100755 server.js diff --git a/app/dist/scripts/api.js b/app/dist/scripts/api.js index 647c630..d16921c 100644 --- a/app/dist/scripts/api.js +++ b/app/dist/scripts/api.js @@ -1,4 +1,4 @@ -/* global Jets */ "use strict"; +"use strict"; /* global document, Jets */ diff --git a/app/dist/scripts/app.js b/app/dist/scripts/app.js index 2414df2..22117c0 100755 --- a/app/dist/scripts/app.js +++ b/app/dist/scripts/app.js @@ -1,4 +1,4 @@ -/* global location, send, window */ "use strict"; +"use strict"; /* global document, history, location, navigator, send, window */ @@ -24,18 +24,6 @@ if ( -if ( // Toggle beta message - localStorage.getItem("hide lbry alert") && - localStorage.getItem("hide lbry alert") === "true" // cannot set Booleans for some reason -) document.querySelector("#alert-beta").style.display = "none"; - -document.querySelector("#close-alert").onclick = function() { - localStorage.setItem("hide lbry alert", true); - document.querySelector("#alert-beta").style.display = "none"; -}; - - - // Smooth scroll document.querySelectorAll("a[href^='#']").forEach(anchor => { anchor.addEventListener("click", event => { diff --git a/app/dist/scripts/plugins/jets.js b/app/dist/scripts/plugins/jets.js index 04e12d4..0b1a750 100644 --- a/app/dist/scripts/plugins/jets.js +++ b/app/dist/scripts/plugins/jets.js @@ -1,4 +1,4 @@ -/* global define */ +/* global define, document, Element, window */ /* ! Jets.js - v0.14.1 - 2018-06-22 * http://NeXTs.github.com/Jets.js/ diff --git a/app/dist/scripts/sockets.js b/app/dist/scripts/sockets.js index c08eb3b..409bca8 100644 --- a/app/dist/scripts/sockets.js +++ b/app/dist/scripts/sockets.js @@ -1,4 +1,4 @@ -"use strict"; +"use strict"; /* global document, location, WebSocket */ diff --git a/app/index.js b/app/index.js index c3c0aec..09c7076 100755 --- a/app/index.js +++ b/app/index.js @@ -1,2 +1,83 @@ -"use strict"; require("@babel/register"); require("@babel/polyfill"); -module.exports = exports = require("./client.js"); +"use strict"; + + + +// P A C K A G E S + +import color from "colorette"; +import compress from "fastify-compress"; +import cors from "cors"; +import fastify from "fastify"; +import helmet from "fastify-helmet"; +import ssr from "choo-ssr/fastify"; +import statik from "fastify-static"; +import websockets from "@inc/fastify-ws"; + +// U T I L S + +import handleSocketMessages from "./sockets"; +import messageSlack from "./helpers/slack"; + +const server = fastify({ + logger: { + level: "warn", + prettyPrint: process.env.NODE_ENV === "development" ? true : false + } +}); + + + +// P R O G R A M + +server + .use(cors()) + .register(compress) + .register(websockets) + .register(helmet, { + hidePoweredBy: { + setTo: "LBRY" + } + }) + .register(statik, { + prefix: "/assets/", + root: `${__dirname}/dist/` + }) + .register(ssr, { + app: require("./client") + }) + .addHook("preHandler", (request, reply, next) => { + if (process.env.NODE_ENV !== "development") { + if (request.headers["x-forwarded-proto"] !== "https") + reply.redirect(302, `https://${request.raw.hostname}${request.raw.originalUrl}`); + + else + next(); + } + + next(); + }) + .ready(err => { + if (err) throw err; + + server.ws.on("connection", socket => { + socket.on("message", data => { + data = JSON.parse(data); + return handleSocketMessages(socket, data); + }); + + socket.on("close", () => socket.terminate()); + }); + }); + + + +// B E G I N + +server.listen(process.env.PORT || 8080, process.env.IP || "0.0.0.0", async() => { + process.env.NODE_ENV === "development" ? + process.stdout.write(`\n— ${color.green("⚡")} ${server.server.address().port}\n`) : + messageSlack({ + message: `Server started at port \`${server.server.address().port}\``, + title: "APP BOOT" + }); +}); diff --git a/app/sass/_layout.scss b/app/sass/_layout.scss index daeea47..bac6ce3 100644 --- a/app/sass/_layout.scss +++ b/app/sass/_layout.scss @@ -72,61 +72,3 @@ hr { code { @include font-mono; } - -.alert { - width: 100%; - bottom: 0; left: 0; - - background-color: $lbry-yellow-3; - line-height: 1.33; - padding-top: 1rem; - padding-right: env(safe-area-inset-right); - padding-bottom: 1rem; - padding-left: env(safe-area-inset-left); - position: fixed; - text-align: left; - z-index: 3; - - > div:first-of-type { - position: relative; - } - - @media (min-width: 901px) { - font-size: 1rem; - } - - @media (max-width: 900px) { - font-size: 0.8rem; - } - - p, - button { - display: inline-block; - } - - p { - width: calc(100% - 2.25rem); - padding-right: 1rem; - } - - a { - font-weight: 600; - text-decoration: underline; - } - - button { - width: 1.25rem; height: 1.25rem; - top: 0; right: 0; - - background-color: $lbry-white; - border-radius: 50%; - display: block; - font-size: 1rem; - line-height: 1; - margin-right: 1rem; - margin-left: 1rem; - // padding-left: 1px; // TODO: Enable this for low-dpi displays - position: absolute; - text-align: center; - } -} diff --git a/index.js b/index.js new file mode 100755 index 0000000..4ad3041 --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +"use strict"; + + + +// P A C K A G E S + +require("@babel/register"); +require("@babel/polyfill"); +require("date-format-lite"); +require("dotenv").config(); + +// U T I L + +require("./app"); diff --git a/package.json b/package.json index 3185506..e9377ab 100755 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "dependencies": { "@babel/polyfill": "^7.2.5", "@inc/fastify-ws": "^1.1.0", - "@octokit/rest": "^16.9.0", + "@octokit/rest": "^16.10.0", "@slack/client": "^4.8.0", "app-root-path": "^2.1.0", "async": "^2.6.1", @@ -26,7 +26,7 @@ "fastify-static": "^1.1.0", "front-matter": "^3.0.1", "fs-exists-sync": "^0.1.0", - "got": "^9.5.1", + "got": "^9.6.0", "graceful-fs": "^4.1.15", "make-promises-safe": "^4.0.0", "markdown-it": "^8.4.2", @@ -82,14 +82,14 @@ "scripts": { "css": "sass --load-path=node_modules --update app/sass:app/dist --style compressed", "format": "eslint '**/*.js' --fix --ignore-pattern '/app/dist/'", - "start": "npm run css && NODE_ENV=production node server", + "start": "npm run css && NODE_ENV=production node", "test": "run-s test:*", "test:dependencies": "updates --update ./ --exclude fastify,prismjs", "test:lint": "standardx --verbose | snazzy", "test:sass": "sass-lint --config ./node_modules/@inc/sasslint-config/config.json --verbose --no-exit", "watch": "run-p watch:*", "watch:sass": "sass --load-path=node_modules --watch app/sass:app/dist --style compressed", - "watch:server": "NODE_ENV=development nodemon server --ignore 'public/'" + "watch:server": "NODE_ENV=development nodemon --ignore 'app/dist'" }, "standardx": { "ignore": [ diff --git a/server.js b/server.js deleted file mode 100755 index d518492..0000000 --- a/server.js +++ /dev/null @@ -1,86 +0,0 @@ -"use strict"; require("dotenv").config(); require("date-format-lite"); require("@babel/register"); require("@babel/polyfill"); - - - -// P A C K A G E S - -const color = require("colorette"); -const cors = require("cors"); -const local = require("app-root-path").require; - -const fastify = require("fastify")({ - logger: { - level: "warn", - prettyPrint: process.env.NODE_ENV === "development" ? true : false - } -}); - -// U T I L S - -const handleSocketMessages = local("app/sockets").default; -const messageSlack = local("app/helpers/slack").default; - - - -// P R O G R A M - -fastify - .use(cors()) - .register(require("fastify-compress")) - .register(require("@inc/fastify-ws")) - .register(require("fastify-helmet"), { - hidePoweredBy: { setTo: "LBRY" } - }) - .register(require("fastify-static"), { - prefix: "/assets/", - root: `${__dirname}/app/dist/` - }) - .register(require("choo-ssr/fastify"), { - app: require("./app") - }) - .addHook("preHandler", (request, reply, next) => { - if (process.env.NODE_ENV !== "development") { - if (request.headers["x-forwarded-proto"] !== "https") - reply.redirect(302, `https://${request.raw.hostname}${request.raw.originalUrl}`); - - else - next(); - } - - next(); - }); - -fastify.ready(err => { - if (err) throw err; - - fastify.ws.on("connection", socket => { - socket.on("message", data => { - data = JSON.parse(data); - return handleSocketMessages(socket, data); - }); - - socket.on("close", () => socket.terminate()); - }); -}); - - - -// B E G I N - -const start = async() => { - try { - await fastify.listen(process.env.PORT || 8080, process.env.IP || "0.0.0.0"); - } catch(err) { - fastify.log.error(err); - process.exit(1); - } - - process.env.NODE_ENV === "development" ? - process.stdout.write(`\n— ${color.green("⚡")} ${fastify.server.address().port}\n`) : - messageSlack({ - message: `Server started at port \`${fastify.server.address().port}\``, - title: "APP BOOT" - }); -}; - -start();