Skip to content

Commit dcbe453

Browse files
committed
Add GitHub authentication with GITHUB_TOKEN environment variable, add TCP to Pino
1 parent 5f45892 commit dcbe453

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ FROM node:19.7-alpine3.17
5353
RUN apk update && apk add --no-cache ca-certificates bash tini
5454
WORKDIR /app/noel/site
5555

56+
COPY --from=server /build/tcp-transport.js /app/noel/site/tcp-transport.js
5657
COPY --from=server /build/node_modules /app/noel/site/node_modules
57-
COPY --from=server /build/server.js /app/noel/site/server.js
5858
COPY --from=server /build/transport.js /app/noel/site/transport.js
59+
COPY --from=server /build/server.js /app/noel/site/server.js
5960
COPY --from=site /build/dist /app/noel/site/dist
6061

6162
RUN addgroup -g 1001 noel && \

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@noel/site",
33
"description": "🐾 Noel's personal website, blog, and documentation site made with Astro",
4-
"version": "12.3.0",
4+
"version": "12.3.1",
55
"private": true,
66
"author": "Noel <[email protected]>",
77
"homepage": "https://floofy.dev",
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@astrojs/mdx": "0.18.0",
20-
"@astrojs/node": "^5.1.0",
20+
"@astrojs/node": "5.1.0",
2121
"@astrojs/tailwind": "3.1.0",
2222
"@fontsource/cantarell": "4.5.10",
2323
"@fontsource/inter": "4.5.15",

server/server.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ const log = pino({
4848
{ target: './transport.js' },
4949

5050
// @ts-ignore
51-
logstashTcpUrl !== undefined
52-
? {
53-
target: 'pino-socket',
54-
options: {
55-
address: logstashTcpUrl,
56-
port: 4040,
57-
mode: 'tcp'
58-
}
59-
}
60-
: undefined
51+
logstashTcpUrl !== undefined ? { target: './tcp-transport.js' } : undefined
6152
].filter(Boolean)
6253
}
6354
});

server/tcp-transport.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* 🐾 @noel/site: Noel's personal website, blog, and documentation site made with Astro
3+
* Copyright (c) 2018-2023 Noel <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
const { formatters } = require('@augu/pino-transport');
25+
const psock = require('pino-socket');
26+
27+
const logstashTcpUrl = process.env.LOGSTASH_TCP_URI;
28+
const logstashTcpPort = process.env.LOGSTASH_TCP_PORT || 4040;
29+
const json = new formatters.Json();
30+
31+
module.exports = () =>
32+
psock({
33+
address: logstashTcpUrl,
34+
port: logstashTcpPort,
35+
mode: 'tcp',
36+
37+
/** @param {Buffer} data */
38+
onBeforeDataWrite(data) {
39+
const payload = JSON.parse(data.toString('utf-8'));
40+
return Buffer.from(json.transform(payload), 'utf-8');
41+
}
42+
});

src/pages/index.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import Page from '../components/Page.astro';
66
77
import '../styles/global.css';
88
9-
const githubRepos = await fetch('https://api.github.com/users/auguwu/repos')
9+
const token = import.meta.env.GITHUB_TOKEN;
10+
const githubRepos = await fetch('https://api.github.com/users/auguwu/repos', {
11+
headers:
12+
token !== undefined
13+
? {
14+
Authorization: `token ${token}`
15+
}
16+
: {}
17+
})
1018
.then((res) => res.json())
1119
.then((data: any[]) =>
1220
data

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ __metadata:
133133
languageName: node
134134
linkType: hard
135135

136-
"@astrojs/node@npm:^5.1.0":
136+
"@astrojs/node@npm:5.1.0":
137137
version: 5.1.0
138138
resolution: "@astrojs/node@npm:5.1.0"
139139
dependencies:
@@ -987,7 +987,7 @@ __metadata:
987987
dependencies:
988988
"@actions/core": 1.10.0
989989
"@astrojs/mdx": 0.18.0
990-
"@astrojs/node": ^5.1.0
990+
"@astrojs/node": 5.1.0
991991
"@astrojs/tailwind": 3.1.0
992992
"@augu/eslint-config": 4.0.1
993993
"@augu/tsconfig": 1.1.1

0 commit comments

Comments
 (0)