mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-10 21:10:54 +01:00
Added Sentry
This commit is contained in:
parent
af844c787a
commit
b3ee42b6fe
9 changed files with 1103 additions and 150 deletions
|
@ -5,4 +5,7 @@ MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com"
|
||||||
API_HOST = "api.fxtwitter.com"
|
API_HOST = "api.fxtwitter.com"
|
||||||
HOST_URL = "https://fxtwitter.com"
|
HOST_URL = "https://fxtwitter.com"
|
||||||
REDIRECT_URL = "https://github.com/dangeredwolf/FixTweet"
|
REDIRECT_URL = "https://github.com/dangeredwolf/FixTweet"
|
||||||
SENTRY_DSN = "https://example@aaaa.ingest.sentry.io/69"
|
SENTRY_DSN = "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@aaaaaa.ingest.sentry.io/69"
|
||||||
|
SENTRY_AUTH_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
|
SENTRY_ORG = "dangeredwolf"
|
||||||
|
SENTRY_PROJECT = "fixtweet"
|
1070
package-lock.json
generated
1070
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -17,6 +17,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^3.14.1",
|
"@cloudflare/workers-types": "^3.14.1",
|
||||||
"@microsoft/eslint-formatter-sarif": "^3.0.0",
|
"@microsoft/eslint-formatter-sarif": "^3.0.0",
|
||||||
|
"@sentry/webpack-plugin": "^1.19.0",
|
||||||
"@types/service-worker-mock": "^2.0.1",
|
"@types/service-worker-mock": "^2.0.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||||
"@typescript-eslint/parser": "^5.31.0",
|
"@typescript-eslint/parser": "^5.31.0",
|
||||||
|
@ -35,8 +36,7 @@
|
||||||
"wrangler": "^2.0.23"
|
"wrangler": "^2.0.23"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/browser": "^7.8.1",
|
"itty-router": "^2.6.1",
|
||||||
"@sentry/tracing": "^7.8.1",
|
"toucan-js": "^2.6.1"
|
||||||
"itty-router": "^2.6.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ export const Constants = {
|
||||||
API_HOST: API_HOST,
|
API_HOST: API_HOST,
|
||||||
HOST_URL: HOST_URL,
|
HOST_URL: HOST_URL,
|
||||||
REDIRECT_URL: REDIRECT_URL,
|
REDIRECT_URL: REDIRECT_URL,
|
||||||
|
RELEASE_NAME: RELEASE_NAME,
|
||||||
API_DOCS_URL: `https://github.com/dangeredwolf/FixTweet/wiki/Status-API`,
|
API_DOCS_URL: `https://github.com/dangeredwolf/FixTweet/wiki/Status-API`,
|
||||||
TWITTER_ROOT: 'https://twitter.com',
|
TWITTER_ROOT: 'https://twitter.com',
|
||||||
TWITTER_API_ROOT: 'https://api.twitter.com',
|
TWITTER_API_ROOT: 'https://api.twitter.com',
|
||||||
|
|
1
src/env.d.ts
vendored
1
src/env.d.ts
vendored
|
@ -7,3 +7,4 @@ declare const MOSAIC_DOMAIN_LIST: string;
|
||||||
declare const API_HOST: string;
|
declare const API_HOST: string;
|
||||||
|
|
||||||
declare const SENTRY_DSN: string;
|
declare const SENTRY_DSN: string;
|
||||||
|
declare const RELEASE_NAME: string;
|
|
@ -1,5 +1,4 @@
|
||||||
import * as Sentry from "@sentry/browser";
|
import Toucan from 'toucan-js';
|
||||||
import { Integrations } from "@sentry/tracing";
|
|
||||||
|
|
||||||
import { Router } from 'itty-router';
|
import { Router } from 'itty-router';
|
||||||
import { Constants } from './constants';
|
import { Constants } from './constants';
|
||||||
|
@ -217,26 +216,44 @@ const cacheWrapper = async (event: FetchEvent): Promise<Response> => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sentryWrapper = async (event: FetchEvent): Promise<void> => {
|
||||||
|
let sentry: null | Toucan = null;
|
||||||
|
|
||||||
|
if (typeof SENTRY_DSN !== 'undefined') {
|
||||||
|
sentry = new Toucan({
|
||||||
|
dsn: SENTRY_DSN,
|
||||||
|
context: event, // Includes 'waitUntil', which is essential for Sentry logs to be delivered. Also includes 'request' -- no need to set it separately.
|
||||||
|
allowedHeaders: /(.*)/,
|
||||||
|
allowedSearchParams: /(.*)/,
|
||||||
|
release: RELEASE_NAME,
|
||||||
|
rewriteFrames: {
|
||||||
|
root: '/'
|
||||||
|
},
|
||||||
|
event
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
event.respondWith((async (): Promise<Response> => {
|
||||||
|
try {
|
||||||
|
return await cacheWrapper(event)
|
||||||
|
} catch(err: unknown) {
|
||||||
|
sentry && sentry.captureException(err);
|
||||||
|
|
||||||
|
return new Response(Strings.ERROR_HTML, {
|
||||||
|
headers: {
|
||||||
|
...Constants.RESPONSE_HEADERS,
|
||||||
|
'content-type': 'text/html',
|
||||||
|
'cache-control': 'max-age=1'
|
||||||
|
},
|
||||||
|
status: 500
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})())
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Event to receive web requests on Cloudflare Worker
|
Event to receive web requests on Cloudflare Worker
|
||||||
*/
|
*/
|
||||||
addEventListener('fetch', (event: FetchEvent) => {
|
addEventListener('fetch', (event: FetchEvent) => {
|
||||||
if (typeof SENTRY_DSN !== 'undefined') {
|
sentryWrapper(event);
|
||||||
Sentry.init({
|
|
||||||
dsn: SENTRY_DSN,
|
|
||||||
debug: true,
|
|
||||||
integrations: [new Integrations.BrowserTracing()],
|
|
||||||
|
|
||||||
tracesSampleRate: 1.0,
|
|
||||||
});
|
|
||||||
console.log('Sentry initialized')
|
|
||||||
} else {
|
|
||||||
console.log('Sentry DSN not defined');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
throw "hi"
|
|
||||||
} catch (e: unknown) {
|
|
||||||
Sentry.captureException(e);
|
|
||||||
}
|
|
||||||
event.respondWith(cacheWrapper(event));
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -235,7 +235,7 @@ ${choice.label} (${choice.percentage}%)
|
||||||
Telegram does not use this. */
|
Telegram does not use this. */
|
||||||
headers.push(
|
headers.push(
|
||||||
`<link rel="alternate" href="${Constants.HOST_URL}/owoembed?text=${encodeURIComponent(
|
`<link rel="alternate" href="${Constants.HOST_URL}/owoembed?text=${encodeURIComponent(
|
||||||
authorText.substr(0, 200)
|
authorText.substring(0, 200)
|
||||||
)}&status=${encodeURIComponent(status)}&author=${encodeURIComponent(
|
)}&status=${encodeURIComponent(status)}&author=${encodeURIComponent(
|
||||||
tweet.author?.screen_name || ''
|
tweet.author?.screen_name || ''
|
||||||
)}" type="application/json+oembed" title="${tweet.author.name}">`
|
)}" type="application/json+oembed" title="${tweet.author.name}">`
|
||||||
|
|
|
@ -34,6 +34,34 @@ export const Strings = {
|
||||||
███ by @dangeredwolf, et al.
|
███ by @dangeredwolf, et al.
|
||||||
-->
|
-->
|
||||||
<head>{headers}</head>`,
|
<head>{headers}</head>`,
|
||||||
|
ERROR_HTML: `<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>:(</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 4em;
|
||||||
|
font-weight: 900;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
font-size:10px;
|
||||||
|
opacity:0.3
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Owie :(</h1>
|
||||||
|
<h2>You hit a snag that broke ${BRANDING_NAME}. It's not your fault though—This is usually caused by a Twitter outage or a new bug.</h2>
|
||||||
|
<p>${RELEASE_NAME}</p>
|
||||||
|
</body>
|
||||||
|
</html>`.replace(/( {2}|\n)/g, ''),
|
||||||
DEFAULT_AUTHOR_TEXT: 'Twitter',
|
DEFAULT_AUTHOR_TEXT: 'Twitter',
|
||||||
|
|
||||||
QUOTE_TEXT: `═ ↘️ Quoting {name} (@{screen_name}) ═════`,
|
QUOTE_TEXT: `═ ↘️ Quoting {name} (@{screen_name}) ═════`,
|
||||||
|
|
|
@ -1,12 +1,68 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
|
||||||
|
|
||||||
|
const gitCommit = require('child_process')
|
||||||
|
.execSync('git rev-parse --short HEAD')
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
const gitBranch = require('child_process')
|
||||||
|
.execSync('git rev-parse --abbrev-ref HEAD')
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
const releaseName = `fixtweet-${gitBranch}-${gitCommit}-${new Date().toISOString().substring(0,19)}`
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
let plugins = [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
BRANDING_NAME: `'${process.env.BRANDING_NAME}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
BRANDING_NAME_DISCORD: `'${process.env.BRANDING_NAME_DISCORD}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
DIRECT_MEDIA_DOMAINS: `'${process.env.DIRECT_MEDIA_DOMAINS}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
HOST_URL: `'${process.env.HOST_URL}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
REDIRECT_URL: `'${process.env.REDIRECT_URL}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
MOSAIC_DOMAIN_LIST: `'${process.env.MOSAIC_DOMAIN_LIST}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
API_HOST: `'${process.env.API_HOST}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
SENTRY_DSN: `'${process.env.SENTRY_DSN}'`
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
RELEASE_NAME: `'${releaseName}'`
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
if (process.env.SENTRY_AUTH_TOKEN) {
|
||||||
|
plugins.push(
|
||||||
|
new SentryWebpackPlugin({
|
||||||
|
release: releaseName,
|
||||||
|
include: './dist',
|
||||||
|
urlPrefix: '~/',
|
||||||
|
ignore: ['node_modules', 'webpack.config.js'],
|
||||||
|
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
worker: './src/server.ts'
|
worker: './src/server.ts'
|
||||||
},
|
},
|
||||||
|
target: 'webworker',
|
||||||
|
devtool: 'source-map',
|
||||||
output: {
|
output: {
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
path: path.join(__dirname, 'dist')
|
path: path.join(__dirname, 'dist')
|
||||||
|
@ -16,32 +72,7 @@ module.exports = {
|
||||||
extensions: ['.ts', '.tsx', '.js'],
|
extensions: ['.ts', '.tsx', '.js'],
|
||||||
fallback: { util: false }
|
fallback: { util: false }
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: plugins,
|
||||||
new webpack.DefinePlugin({
|
|
||||||
BRANDING_NAME: `'${process.env.BRANDING_NAME}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
BRANDING_NAME_DISCORD: `'${process.env.BRANDING_NAME_DISCORD}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
DIRECT_MEDIA_DOMAINS: `'${process.env.DIRECT_MEDIA_DOMAINS}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
HOST_URL: `'${process.env.HOST_URL}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
REDIRECT_URL: `'${process.env.REDIRECT_URL}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
MOSAIC_DOMAIN_LIST: `'${process.env.MOSAIC_DOMAIN_LIST}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
API_HOST: `'${process.env.API_HOST}'`
|
|
||||||
}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
SENTRY_DSN: `'${process.env.SENTRY_DSN}'`
|
|
||||||
})
|
|
||||||
],
|
|
||||||
optimization: {
|
optimization: {
|
||||||
mangleExports: 'size'
|
mangleExports: 'size'
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue