Skip to content

Commit

Permalink
configmaps - secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi2krishna committed Sep 20, 2023
1 parent 1383e26 commit a5d7a68
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ COPY . .
RUN npx prisma generate
RUN npm run build
# Expose port
EXPOSE 8080
EXPOSE 3000
# Start app
CMD [ "npm", "start" ]
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": "true",
"scripts": {
"lint": "eslint src/",
"start": "prisma migrate deploy && node build/index.js",
"start": "node build/index.js",
"build": "tsc",
"dev": "ts-node-dev --respawn --pretty --transpile-only --exit-child src/index.ts",
"test": "echo \"Error: no test specified\"",
Expand Down
4 changes: 2 additions & 2 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ app.use(cors());
app.use(express.json());

// Routers
app.use("/api", healthchecksRouter);
app.use("/api/courses", coursesRouter);
app.use("/", healthchecksRouter);
app.use("/courses", coursesRouter);

// Error and 404
app.use(errorHandler);
Expand Down
23 changes: 23 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import app from "./app";
import { getConfig } from "./common/config";
import { execSync } from "child_process";
import path from "path";

if (!getConfig("PORT")) {
process.exit(1);
Expand All @@ -8,6 +10,27 @@ if (!getConfig("PORT")) {
const PORT: number = parseInt(getConfig("PORT") as string, 10);

async function main() {
// Build the database connection string
console.log("Building database connection string");
const dbHost = getConfig("DB_HOST") || "localhost";
const dbPort = getConfig("DB_PORT") || 5432;
const dbName = getConfig("DB_NAME") || "postgres";
const dbUser = getConfig("DB_USER") || "postgres";
const dbPassword = getConfig("DB_PASSWORD") || "password";
const dbConnectionString = `postgres://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/${dbName}`;
// Set DATABASE_URL environment variable
process.env.DATABASE_URL = dbConnectionString;

// Run prisma migrations
console.log("Migrating database...");
execSync(
`export DATABASE_URL=${dbConnectionString} && npx prisma migrate deploy --schema ${path.join(
__dirname,
"../prisma/schema.prisma"
)}`,
{ stdio: "inherit" }
);

// Start the server
app.listen(PORT, () => {
console.log(`🚀 App started in ${getConfig("MODE")} mode on port ${PORT}.`);
Expand Down
2 changes: 1 addition & 1 deletion webapp/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_API_URL=http://localhost:8080/api
VITE_API_URL=http://localhost:8080
31 changes: 11 additions & 20 deletions webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/dl-logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Digital Lync LMS</title>
<style>
body {
color: 'white';
background-color: red;
}
</style>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/dl-logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Digital Lync LMS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
2 changes: 0 additions & 2 deletions webapp/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
server {
listen 80;
listen 3000;
listen [::]:80;
listen [::]:3000;
server_name localhost;

#access_log /var/log/nginx/host.access.log main;
Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webapp",
"private": true,
"version": "2.1",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down

0 comments on commit a5d7a68

Please sign in to comment.