Skip to content

Commit 838f73e

Browse files
committed
fix favicon missing log
1 parent 6a52da9 commit 838f73e

File tree

5 files changed

+358
-16
lines changed

5 files changed

+358
-16
lines changed

src/api/esbuild.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { build, context } from 'esbuild';
22
import { readFileSync } from 'fs';
33
import { resolve } from 'path';
4+
import copyStaticFiles from 'esbuild-copy-static-files';
45

56
const isWatching = !!process.argv.includes('--watch')
67
const nodePackage = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json'), 'utf8'));
@@ -24,14 +25,17 @@ const buildOptions = {
2425
},
2526
banner: {
2627
js: `
27-
import path from 'path';
2828
import { fileURLToPath } from 'url';
2929
import { createRequire as topLevelCreateRequire } from 'module';
3030
const require = topLevelCreateRequire(import.meta.url);
3131
const __filename = fileURLToPath(import.meta.url);
3232
const __dirname = path.dirname(__filename);
3333
`.trim(),
3434
}, // Banner for compatibility with CommonJS
35+
plugins: [copyStaticFiles({
36+
src: './public',
37+
dest: resolve(process.cwd(), '../', '../', 'dist_devel', 'public'),
38+
})],
3539
};
3640

3741
if (isWatching) {

src/api/index.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { randomUUID } from "crypto";
33
import fastify, { FastifyInstance } from "fastify";
44
import FastifyAuthProvider from "@fastify/auth";
5+
import fastifyStatic from "@fastify/static";
56
import fastifyAuthPlugin from "./plugins/auth.js";
67
import protectedRoute from "./routes/protected.js";
78
import errorHandlerPlugin from "./plugins/errorHandler.js";
@@ -24,23 +25,35 @@ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2425
import mobileWalletRoute from "./routes/mobileWallet.js";
2526
import stripeRoutes from "./routes/stripe.js";
2627
import membershipPlugin from "./routes/membership.js";
28+
import path from "path"; // eslint-disable-line import/no-nodejs-modules
2729

2830
dotenv.config();
2931

3032
const now = () => Date.now();
3133

32-
async function init() {
34+
async function init(prettyPrint: boolean = false) {
3335
const dynamoClient = new DynamoDBClient({
3436
region: genericConfig.AwsRegion,
3537
});
3638

3739
const secretsManagerClient = new SecretsManagerClient({
3840
region: genericConfig.AwsRegion,
3941
});
40-
42+
const transport = prettyPrint
43+
? {
44+
target: "pino-pretty",
45+
options: {
46+
colorize: true,
47+
translateTime: "SYS:standard",
48+
ignore: "pid,hostname",
49+
singleLine: false,
50+
},
51+
}
52+
: undefined;
4153
const app: FastifyInstance = fastify({
4254
logger: {
4355
level: process.env.LOG_LEVEL || "info",
56+
transport,
4457
},
4558
rewriteUrl: (req) => {
4659
const url = req.url;
@@ -71,6 +84,10 @@ async function init() {
7184
await app.register(fastifyZodValidationPlugin);
7285
await app.register(FastifyAuthProvider);
7386
await app.register(errorHandlerPlugin);
87+
await app.register(fastifyStatic, {
88+
root: path.join(__dirname, "public"),
89+
prefix: "/",
90+
});
7491
if (!process.env.RunEnvironment) {
7592
process.env.RunEnvironment = "dev";
7693
}
@@ -104,7 +121,6 @@ async function init() {
104121
);
105122
done();
106123
});
107-
app.get("/", (_, reply) => reply.send("Welcome to the ACM @ UIUC Core API!"));
108124
app.get("/api/v1/healthz", (_, reply) => reply.send({ message: "UP" }));
109125
await app.register(
110126
async (api, _options) => {
@@ -143,7 +159,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
143159
);
144160
process.exit(1);
145161
}
146-
const app = await init();
162+
const app = await init(true);
147163
app.listen({ port: 8080 }, async (err) => {
148164
/* eslint no-console: ["error", {"allow": ["log", "error"]}] */
149165
if (err) console.error(err);

src/api/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@fastify/aws-lambda": "^5.0.0",
2727
"@fastify/caching": "^9.0.1",
2828
"@fastify/cors": "^10.0.1",
29+
"@fastify/static": "^8.1.1",
2930
"@middy/core": "^6.0.0",
3031
"@middy/event-normalizer": "^6.0.0",
3132
"@middy/sqs-partial-batch-failure": "^6.0.0",
@@ -57,6 +58,8 @@
5758
"@tsconfig/node22": "^22.0.0",
5859
"@types/aws-lambda": "^8.10.147",
5960
"@types/qrcode": "^1.5.5",
60-
"nodemon": "^3.1.9"
61+
"esbuild-copy-static-files": "^0.1.0",
62+
"nodemon": "^3.1.9",
63+
"pino-pretty": "^13.0.0"
6164
}
6265
}

src/api/public/favicon.ico

15 KB
Binary file not shown.

0 commit comments

Comments
 (0)