-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #44 Express quickstart add Nodejs. Limit app cpu
- Loading branch information
1 parent
8bbf237
commit 6891dc1
Showing
10 changed files
with
913 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ venv | |
*.db | ||
target | ||
workspace | ||
node_modules |
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
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
14 changes: 14 additions & 0 deletions
14
repo-template-files/quickstarts/express-quickstart/src/Dockerfile
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,14 @@ | ||
FROM node:20-alpine | ||
|
||
WORKDIR /app/src | ||
COPY . /app/src | ||
|
||
RUN npm install | ||
|
||
RUN chown -R node:node /app | ||
|
||
USER node | ||
|
||
ENTRYPOINT /app/src/entrypoint.sh | ||
|
||
EXPOSE 3000 |
3 changes: 3 additions & 0 deletions
3
repo-template-files/quickstarts/express-quickstart/src/entrypoint.sh
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,3 @@ | ||
#!/bin/sh | ||
|
||
exec node index.js |
47 changes: 47 additions & 0 deletions
47
repo-template-files/quickstarts/express-quickstart/src/index.js
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,47 @@ | ||
const express = require("express") | ||
const app = express() | ||
const port = 3000 | ||
|
||
const mysql = require('mysql2') | ||
|
||
DB_USER = process.env.DB_USER; | ||
DB_PASSWORD = process.env.DB_PASSWORD; | ||
DB_HOST = process.env.DB_HOST; | ||
DB_PORT = process.env.DB_PORT; | ||
DB_NAME = process.env.DB_NAME; | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Hello World!<br />Check /health to verify database connection is also OK") | ||
}) | ||
|
||
app.get("/health", (req, res) => { | ||
// Create connection to database | ||
// Get database settings from environment | ||
let health = "BAD" | ||
const connection = mysql.createConnection({ | ||
host: DB_HOST, | ||
port: DB_PORT, | ||
user: DB_USER, | ||
database: DB_NAME, | ||
password: DB_PASSWORD, | ||
}); | ||
|
||
connection.query( | ||
'SELECT NOW() AS now', | ||
function (err, results, fields) { | ||
if (err) { | ||
console.error(err) | ||
res.send(health) | ||
} else { | ||
console.log(results) // results contains rows returned by server | ||
console.log(fields) // fields contains extra meta data about results, if available | ||
health = "OK" | ||
res.send(health) | ||
} | ||
} | ||
); | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`) | ||
}) |
Oops, something went wrong.