blob: 6885ee574d60d724acf942793e3c2dc9c125305d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
const express = require("express");
const path = require("node:path");
const geddit = require("./geddit.js");
const { Database } = require("bun:sqlite");
const db = new Database("readit.db");
const createUsers = db.query(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE,
password_hash TEXT
)
`);
createUsers.run();
const createSubs = db.query(`
CREATE TABLE IF NOT EXISTS subscriptions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
subreddit TEXT,
FOREIGN KEY(user_id) REFERENCES users(id),
UNIQUE(user_id, subreddit)
)
`);
createSubs.run();
module.exports = { db };
const app = express();
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
const routes = require("./routes/index");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.use("/", routes);
const port = process.env.READIT_PORT;
const server = app.listen(port ? port : 3000, () => {
console.log(`started on ${server.address().port}`);
});
|