Skip to content

Commit 0556380

Browse files
add endpoint for getting trcacking
1 parent 03d35a2 commit 0556380

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
echo "MONGO_URI=${{ secrets.MONGO_URI }}" >> ./envfile
7171
echo "WORKERS_REPLICAS=${{ vars.WORKERS_REPLICAS }}" >> ./envfile
7272
echo "RESEND_TOKEN=${{ secrets.RESEND_TOKEN }}" >> ./envfile
73+
echo "API_TOKEN=${{ secrets.API_TOKEN }}"
7374
7475
- name: Docker Stack Deploy
7576
uses: cssnr/stack-deploy-action@v1

docker-stack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23limwK0oEIzSCUExe
1414
- NUXT_MONGO_URI=${MONGO_URI}
1515
- NUXT_RESEND_TOKEN=${RESEND_TOKEN}
16+
- NUXT_API_TOKEN=${API_TOKEN}
1617
secrets:
1718
- source: nest2d_stripe_secret_key
1819
target: stripe_secret_key

nuxt.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ export default defineNuxtConfig({
1111
runtimeConfig: {
1212
mongoUri: '',
1313
stripeSecretKey: '',
14-
githubClientSecret: '',
1514
resendToken: '',
15+
apiToken: '',
1616
public: {
1717
baseUrl: "http://localhost:3000",
1818
gitCommitSha: "",
1919
googleClientId: "",
20-
githubClientId: "",
2120
},
2221
},
2322

server/api/track/all.get.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineEventHandler } from 'h3'
2+
import { connectDB } from '~~/server/db/mongo'
3+
4+
export default defineEventHandler(async (event) => {
5+
const config = useRuntimeConfig()
6+
const apiToken = config.apiToken
7+
8+
const authHeader = event.node.req.headers['authorization'] || (event.node.req.headers['Authorization'] as string)
9+
if (!authHeader || !authHeader.startsWith('api ') || authHeader.slice(4).trim() !== apiToken) {
10+
throw createError({
11+
statusCode: 401,
12+
statusText: 'unauth',
13+
})
14+
}
15+
16+
const db = await connectDB()
17+
const records = await db.collection('tracking').find().sort({ timestamp: -1 }).toArray()
18+
const result = records.map((record) => ({
19+
...record,
20+
timestamp: record.timestamp instanceof Date ? record.timestamp.toISOString() : record.timestamp,
21+
}))
22+
return result
23+
})

0 commit comments

Comments
 (0)