Initial commit

This commit is contained in:
Rogerio Chaves 2020-04-04 15:32:27 +02:00
commit 621b31d27c
No known key found for this signature in database
GPG Key ID: E6AF5440509B1D94
7 changed files with 9612 additions and 0 deletions

21
app/index.js Normal file
View File

@ -0,0 +1,21 @@
let server = require("./lib/express");
require("./lib/ssb");
require("./lib/electron");
if (process.env.NODE_ENV !== "production") {
const chokidar = require("chokidar");
const watcher = chokidar.watch("./lib");
const { BrowserWindow } = require("electron");
watcher.on("ready", () => {
watcher.on("all", () => {
console.log("Clearing /lib/ module cache from server");
Object.keys(require.cache).forEach((id) => {
if (/[\/\\]lib[\/\\]/.test(id)) delete require.cache[id];
});
server.close();
server = require("./lib/express");
BrowserWindow.getAllWindows()[0].reload();
});
});
}

33
app/lib/electron.js Normal file
View File

@ -0,0 +1,33 @@
const { app, BrowserWindow } = require("electron");
const createWindow = () => {
// Create the browser window.
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
win.loadURL("http://localhost:3000");
};
app.whenReady().then(createWindow);
// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

22
app/lib/express.js Normal file
View File

@ -0,0 +1,22 @@
const express = require("express");
const app = express();
const port = 3000;
app.set("view engine", "ejs");
app.use(express.static("public"));
app.get("/", (_req, res) => {
res.render("index", { message: "Hello there21!" });
});
app.post("/publish", (req, res) => {
console.log("req.body", req.body);
res.redirect("/");
});
const server = app.listen(port, () =>
console.log(`Example app listening at http://localhost:${port}`)
);
module.exports = server;

21
app/lib/ssb.js Normal file
View File

@ -0,0 +1,21 @@
const Server = require("ssb-server");
const config = require("ssb-config");
const fs = require("fs");
const path = require("path");
// add plugins
Server.use(require("ssb-master"))
.use(require("ssb-gossip"))
.use(require("ssb-replicate"))
.use(require("ssb-backlinks"));
const server = Server(config);
console.log("SSB server started at", config.port);
// save an updated list of methods this server has made public
// in a location that ssb-client will know to check
const manifest = server.getManifest();
fs.writeFileSync(
path.join(config.path, "manifest.json"), // ~/.ssb/manifest.json
JSON.stringify(manifest)
);

9473
app/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

27
app/package.json Normal file
View File

@ -0,0 +1,27 @@
{
"name": "social-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"chokidar": "^3.3.1",
"ejs": "^3.0.2",
"express": "^4.17.1",
"pull-stream": "^3.6.14",
"ssb-backlinks": "^1.0.0",
"ssb-client": "^4.9.0",
"ssb-config": "^3.4.4",
"ssb-gossip": "^1.1.1",
"ssb-master": "^1.0.3",
"ssb-replicate": "^1.3.2",
"ssb-server": "^15.2.0"
},
"devDependencies": {
"electron": "^8.2.0"
}
}

15
app/views/index.ejs Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Social</title>
</head>
<body>
<form action="publish" method="POST">
<textarea name="message"></textarea>
<input type="submit" value="Send" />
</form>
<h1><%= message %></h1>
</body>
</html>