Skip to content

Commit

Permalink
chore: add logs and fix netlify redirect api
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Dec 13, 2024
1 parent c18c484 commit ff7a5c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion functions/balance.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export const config: Config = {
path: '/api/balance/:network/:chain_name',
};

export default async (req: Request, context: Context) => {
export default async (_req: Request, context: Context) => {
const { network, chain_name } = context.params;

const mnemonic = Netlify.env.get('MNEMONIC');
if (!mnemonic) {
console.log(`[ERROR] env: MNEMONIC is missing`);
return new Response(JSON.stringify({ error: `env: MNEMONIC is missing` }), {
status: 503,
});
Expand All @@ -22,6 +23,7 @@ export default async (req: Request, context: Context) => {
try {
chain = await import(`../chains/${network}/${chain_name}.json`);
} catch (err) {
console.log(`[ERROR] ${network}/${chain_name} not found`);
return new Response(
JSON.stringify({ error: `${network}/${chain_name} not found` }),
{
Expand All @@ -48,6 +50,9 @@ export default async (req: Request, context: Context) => {
address: acc.address,
});
} catch (err) {
console.log(
`[ERROR] failed to get balance of account: ${acc.address}, ${err}`,
);
return new Response(JSON.stringify({ error: err }), {
status: 500,
});
Expand Down
5 changes: 5 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[build]
functions = "./functions"

[[redirects]]
from = "/api/*"
to = "/api/:splat"
status = 200

[[redirects]]
from = "/*"
to = "/index.html"
Expand Down

0 comments on commit ff7a5c9

Please sign in to comment.