File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments