Skip to content

Commit

Permalink
esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
tubone24 committed Mar 11, 2024
1 parent e9cfdaa commit 3964d2c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
90 changes: 47 additions & 43 deletions functions/src/cors-proxy-github.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
import axios from "axios";
// import * as Sentry from "@sentry/node";
// import "@sentry/tracing";
import * as Sentry from "@sentry/node";
import "@sentry/tracing";
import { ProfilingIntegration } from "@sentry/profiling-node";

// Sentry.init({
// dsn: "https://[email protected]/6347154",
// tracesSampleRate: 1.0,
// integrations: [new ProfilingIntegration()],
// profilesSampleRate: 1.0,
// });
Sentry.init({
dsn: "https://[email protected]/6347154",
tracesSampleRate: 1.0,
integrations: [new ProfilingIntegration()],
profilesSampleRate: 1.0,
});

// const transaction = Sentry.startTransaction({
// op: "blog",
// name: "github cors transaction",
// });
const transaction = Sentry.startTransaction({
op: "blog",
name: "github cors transaction",
});

exports.handler = (event, context) => {
exports.handler = async (event, context) => {
console.log(context);
const body = JSON.parse(event.body);
const headers = {
accept: "application/json",
Accept: "application/json",
'Content-Type': 'application/json',

Check failure on line 22 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'Content-Type':·'application/json'` with `"Content-Type":·"application/json"`
};
return axios
.post("https://github.com/login/oauth/access_token", body, { headers })
.then((response) => {
console.log({
access_token: `${response.data.access_token.substring(
0,
3
)}xxxxxxxxxxxxxxxxx`,
token_type: response.data.token_type,
scope: response.data.scope,
});
// transaction.finish();
return {
statusCode: 200,
body: JSON.stringify({
access_token: response.data.access_token,
token_type: response.data.token_type,
scope: response.data.scope,
}),
};
})
.catch((error) => {
// Sentry.captureException(error);
// transaction.finish();
return {
statusCode: 500,
body: JSON.stringify({ error }),
};

try {
const response = await fetch("https://github.com/login/oauth/access_token", {

Check failure on line 26 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

method: 'POST',

Check failure on line 27 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

Replace `······method:·'POST'` with `········method:·"POST"`
headers: headers,

Check failure on line 28 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
body: JSON.stringify(body),

Check failure on line 29 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
});

Check failure on line 30 in functions/src/cors-proxy-github.js

View workflow job for this annotation

GitHub Actions / lint

Replace `}` with `··}⏎····`
const data = await response.json();

console.log({
access_token: `${data.access_token.substring(0, 3)}xxxxxxxxxxxxxxxxx`,
token_type: data.token_type,
scope: data.scope,
});

transaction.finish();

return {
statusCode: 200,
body: JSON.stringify({
access_token: data.access_token,
token_type: data.token_type,
scope: data.scope,
}),
};
} catch (error) {
Sentry.captureException(error);
transaction.finish();
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
};
3 changes: 0 additions & 3 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

[[plugins]]
package = "netlify-plugin-gatsby-cache"

[functions]
node_bundler = "esbuild"

0 comments on commit 3964d2c

Please sign in to comment.