-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e4f9c6
commit b91ca02
Showing
19 changed files
with
1,257 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ client/out/ | |
|
||
# production | ||
client/build | ||
server/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
import { auth } from "@/auth/resource"; | ||
import { data } from "@/data/resource"; | ||
import { defineBackend } from "@aws-amplify/backend"; | ||
|
||
defineBackend({ | ||
auth, | ||
data, | ||
}); | ||
defineBackend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"type": "module", | ||
"devDependencies": { | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.2", | ||
"pinst": "^3.0.0" | ||
"scripts": { | ||
"dev": "npx next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"paths": { | ||
"@/*": [ | ||
"./src/*", | ||
], | ||
"@/amplify/*": [ | ||
"../amplify/*" | ||
] | ||
}, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
"noEmit": true, | ||
"jsx": "preserve", | ||
"baseUrl": "./src" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.tsx", | ||
"src/.next/types/**/*.ts", | ||
], | ||
"exclude": [ | ||
"../server" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
es2021: true, | ||
}, | ||
extends: ["eslint:recommended"], | ||
rules: { | ||
"no-unused-vars": ["warn", { argsIgnorePattern: "_" }], | ||
}, | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [".eslintrc.{js,cjs}"], | ||
parserOptions: { | ||
sourceType: "script", | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"start": "node .", | ||
"build": "npm-run-all clean tsc", | ||
"dev:start": "npm-run-all build start", | ||
"dev": "NODE_ENV=development nodemon --watch src -e ts,ejs --exec npm run dev:start", | ||
"tsc": "tsc -p ./tsconfig.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type Request, type Response } from "express"; | ||
|
||
import { createApplicationLogger } from "@/utils/logger"; | ||
|
||
export const getHealth = (request: Request, response: Response) => { | ||
const logger = createApplicationLogger( | ||
"health.controller.ts", | ||
request, | ||
response, | ||
); | ||
logger.info(`ENTRY - ${request.method} ${request.url}`); | ||
const data = { | ||
uptime: process.uptime() + " seconds", | ||
message: "OK", | ||
date: new Date(), | ||
}; | ||
logger.info(`EXIT - ${request.method} ${request.url} - ${200}`); | ||
|
||
return response.status(200).json(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import axios from "axios"; | ||
import axiosRetry from "axios-retry"; | ||
import dotenv from "dotenv"; | ||
import express from "express"; | ||
import http from "http"; | ||
|
||
import router from "@/routes/health.route"; | ||
import { | ||
createLightweightApplicationLogger, | ||
shutdownLoggers, | ||
} from "@/utils/logger"; | ||
import { type TerminusOptions, createTerminus } from "@godaddy/terminus"; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use("/", router); | ||
|
||
const logger = createLightweightApplicationLogger("index.ts"); | ||
|
||
axiosRetry(axios, { | ||
retries: 2, | ||
retryDelay: (retryCount) => { | ||
return retryCount * 1000; // time interval between retries | ||
}, | ||
retryCondition(error) { | ||
return error.code === "ECONNABORTED"; | ||
}, | ||
|
||
onRetry: (retryCount) => { | ||
logger.warn(`Retrying axios call. Retry count: `, retryCount); | ||
}, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
const onSignal = async () => { | ||
logger.info("🚀 Server is starting cleanup"); | ||
try { | ||
logger.info("Kafka Consumer Disconnected"); | ||
} catch (err) { | ||
logger.error("Error disconnecting the kafka consumer", err as Error); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
const onShutdown = async () => { | ||
logger.info("Cleanup finished, 🚀 server is shutting down"); | ||
}; | ||
|
||
const gracefullyShutdown = (signal: string) => { | ||
logger.info(`${signal} signal received: closing HTTP server.`); | ||
server.close(() => { | ||
logger.info("Closing remaining resources, then closing HTTP server."); | ||
shutdownLoggers(); // Ensure any remaining async writes have finished. | ||
}); | ||
}; | ||
|
||
const terminusOption: TerminusOptions = { | ||
onSignal, | ||
onShutdown, | ||
timeout: 12 * 1000, // waits before closing the server | ||
signals: ["SIGINT", "SIGTERM", "SIGUSR2"], | ||
}; | ||
|
||
export const server = createTerminus(http.createServer(app), terminusOption); | ||
|
||
process.on("SIGQUIT", gracefullyShutdown); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from "express"; | ||
|
||
import * as controllers from "@/controllers/health.controller"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/health", controllers.getHealth); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import server from "@/index.js"; | ||
import { createLightweightApplicationLogger } from "@/utils/logger"; | ||
|
||
const logger = createLightweightApplicationLogger("server.ts"); | ||
const port = process.env.SERVER_PORT; | ||
|
||
server | ||
.listen(port, () => { | ||
logger.info(`Server is listening on port ${port}`); | ||
|
||
logger.info(`Process ID: ${process.pid}`); | ||
logger.info(`Node Version: ${process.version}`); | ||
logger.info(`Server Port: ${port}`); | ||
logger.info(`Debug Port: ${process.debugPort}`); | ||
}) | ||
.on("error", (error: Error) => { | ||
logger.error(error.message); | ||
throw error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
// any constants go here | ||
export const environment = { | ||
nodeEnv: process.env.ENV || process.env.NODE_ENV, | ||
logDir: process.env.LOG_DIR || "logs", | ||
logLevel: process.env.LOG_LEVEL || "info", | ||
logFile: process.env.LOG_FILE || "app.log", | ||
}; |
Oops, something went wrong.