22import { randomUUID } from "crypto" ;
33import fastify , { FastifyInstance } from "fastify" ;
44import FastifyAuthProvider from "@fastify/auth" ;
5+ import fastifyStatic from "@fastify/static" ;
56import fastifyAuthPlugin from "./plugins/auth.js" ;
67import protectedRoute from "./routes/protected.js" ;
78import errorHandlerPlugin from "./plugins/errorHandler.js" ;
@@ -24,23 +25,35 @@ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2425import mobileWalletRoute from "./routes/mobileWallet.js" ;
2526import stripeRoutes from "./routes/stripe.js" ;
2627import membershipPlugin from "./routes/membership.js" ;
28+ import path from "path" ; // eslint-disable-line import/no-nodejs-modules
2729
2830dotenv . config ( ) ;
2931
3032const 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 ) ;
0 commit comments