aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorAkshay" (aider) <[email protected]>2024-11-08 22:10:47 +0000
committerAkshay" (aider) <[email protected]>2024-11-08 22:10:47 +0000
commit5cfd8d35ac937799dcf6079b3412e6f2d76b6a4f (patch)
treeff974d62974a0725b53fd1c917c7de93be4959a7 /src/index.js
parentc3782a25b368c220299f70ba4dafd7bfa8f71c9e (diff)
feat: Add user registration, login, and subscription management with SQLite
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
index cf55183..bb9eb53 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,15 +2,36 @@ const express = require("express");
2const path = require("node:path"); 2const path = require("node:path");
3const routes = require("./routes/index"); 3const routes = require("./routes/index");
4const geddit = require("./geddit.js"); 4const geddit = require("./geddit.js");
5const { Database } = require("bun:sqlite");
5 6
6const app = express(); 7const app = express();
7 8
8app.set("views", path.join(__dirname, "views")); 9app.set("views", path.join(__dirname, "views"));
9app.set("view engine", "pug"); 10app.set("view engine", "pug");
10 11
12app.use(express.json());
11app.use(express.static(path.join(__dirname, "public"))); 13app.use(express.static(path.join(__dirname, "public")));
12app.use("/", routes); 14app.use("/", routes);
13 15
16const db = new Database("users.db");
17
18db.run(`
19 CREATE TABLE IF NOT EXISTS users (
20 id INTEGER PRIMARY KEY AUTOINCREMENT,
21 username TEXT UNIQUE,
22 password TEXT
23 )
24`);
25
26db.run(`
27 CREATE TABLE IF NOT EXISTS subscriptions (
28 id INTEGER PRIMARY KEY AUTOINCREMENT,
29 user_id INTEGER,
30 subreddit TEXT,
31 FOREIGN KEY(user_id) REFERENCES users(id)
32 )
33`);
34
14const port = process.env.READIT_PORT; 35const port = process.env.READIT_PORT;
15const server = app.listen(port ? port : 3000, () => { 36const server = app.listen(port ? port : 3000, () => {
16 console.log(`started on ${server.address().port}`); 37 console.log(`started on ${server.address().port}`);