Closes #207 and reformats some things

This commit is contained in:
ポール ウェッブ 2019-01-17 14:41:26 -06:00
parent 0e0bf9a4a3
commit 1e850048bd
9 changed files with 105 additions and 166 deletions

View file

@ -1,4 +1,4 @@
/* global Jets */ "use strict";
"use strict"; /* global document, Jets */

View file

@ -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 => {

View file

@ -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/

View file

@ -1,4 +1,4 @@
"use strict";
"use strict"; /* global document, location, WebSocket */

View file

@ -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"
});
});

View file

@ -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;
}
}

14
index.js Executable file
View file

@ -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");

View file

@ -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": [

View file

@ -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();