lbry.tech/client.js

64 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-07-12 17:21:42 +02:00
"use strict";
// P A C K A G E S
const async = require("choo-async");
const bundles = require("choo-bundles");
const choo = require("choo");
const data = require("choo-data");
const devtools = require("choo-devtools");
const ssr = require("choo-ssr");
// V A R I A B L E S
const head = require("./views/partials/head");
const html = require("./views/components/html");
const layout = require("./views/components/layout");
// P R O G R A M
2018-07-13 23:58:24 +02:00
function main() {
2018-07-12 17:21:42 +02:00
const app = async(choo());
app.use(ssr());
app.use(data());
app.use(bundles());
if (process.env.NODE_ENV !== "production") app.use(devtools());
const page = content => (html(
ssr.head(
head(),
bundles.assets()
),
ssr.body(
async.catch(
layout(content),
2018-07-13 23:58:24 +02:00
require("./views/pages/error")(app)
2018-07-12 17:21:42 +02:00
),
2018-07-13 23:58:24 +02:00
ssr.state()
2018-07-12 17:21:42 +02:00
)
));
app.route("/", page(require("./views/pages/home")(app)));
app.route("/resources", page(require("./views/pages/resources")(app)));
app.route("/*", page(require("./views/pages/page")(app)));
return app;
}
if (typeof window !== "undefined") {
const app = main();
app.mount("html");
}
// E X P O R T
module.exports = exports = main;