diff options
| author | Andrew Lee <andrew@alee14.me> | 2026-04-20 16:19:09 -0400 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2026-04-20 16:19:09 -0400 |
| commit | 98805430b78fa24a7d80808c50f3c38a3a748f07 (patch) | |
| tree | 6362690ecd724989867a044033bc84622f955a8a /api | |
| parent | f8b93cf133126b57d85d8a5fc424fc87ad2f4459 (diff) | |
| download | bnbmc-announcement-api-98805430b78fa24a7d80808c50f3c38a3a748f07.tar.gz bnbmc-announcement-api-98805430b78fa24a7d80808c50f3c38a3a748f07.tar.bz2 bnbmc-announcement-api-98805430b78fa24a7d80808c50f3c38a3a748f07.zip | |
attachment support; santitized input; docker support
Diffstat (limited to 'api')
| -rw-r--r-- | api/Dockerfile | 12 | ||||
| -rwxr-xr-x | api/bun.lockb | bin | 30656 -> 31778 bytes | |||
| -rw-r--r-- | api/index.ts | 13 | ||||
| -rw-r--r-- | api/package.json | 2 |
4 files changed, 27 insertions, 0 deletions
diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..a7a7d62 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,12 @@ +FROM bun:latest + +WORKDIR /api + +COPY bun.lockd . +COPY package.json . + +RUN bun install + +COPY . . + +ENTRYPOINT ["bun", "index.ts"] diff --git a/api/bun.lockb b/api/bun.lockb Binary files differindex 52c0b95..9d47e1d 100755 --- a/api/bun.lockb +++ b/api/bun.lockb diff --git a/api/index.ts b/api/index.ts index 2fb7a08..9435bb1 100644 --- a/api/index.ts +++ b/api/index.ts @@ -1,10 +1,13 @@ import express from 'express'; import { Database } from "bun:sqlite"; +import cors from 'cors'; const app = express(); const port = process.env.PORT || 3000; const db = new Database("../database.sqlite", { readonly: true }); +app.use(express.static('../public')) +app.use(cors()); app.get('/', (req, res) => { const query = db.prepare(`SELECT * FROM announcements ORDER BY created_at DESC`); @@ -12,6 +15,16 @@ app.get('/', (req, res) => { res.send(result); }); +app.get('/attachments/:slug', (req, res) => { + if (req.params.slug) { + const query = db.prepare(`SELECT * FROM announcements_attachments WHERE msg_id = (?)`); + const result = query.all(req.params.slug); + res.send(result); + } else { + res.send('Unknown message id.'); + } +}); + app.listen(port, () => { console.log(`Server is running on port ${port}`); }); diff --git a/api/package.json b/api/package.json index c9b6a1e..8fcc3ed 100644 --- a/api/package.json +++ b/api/package.json @@ -4,10 +4,12 @@ "main": "index.js", "license": "MIT", "dependencies": { + "cors": "^2.8.6", "express": "^5.2.1" }, "devDependencies": { "@types/bun": "^1.3.11", + "@types/cors": "^2.8.19", "@types/express": "^5.0.6", "@types/node": "^25.5.2" } |
