1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-26 10:43:35 +02:00

react-express-mysql: get version from mysql

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
Jérémie Drouet 2020-03-24 10:48:45 +01:00
parent 75aa52524c
commit 59724f87a1
8 changed files with 545 additions and 183 deletions

View file

@ -1,5 +1,18 @@
const fs = require("fs");
const readFileSync = filename => fs.readFileSync(filename).toString("utf8");
// Constants
module.exports = {
database: {
host: process.env.DATABASE_HOST || "localhost",
port: process.env.DATABASE_PORT,
database: process.env.DATABASE_DB,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD
? readFileSync(process.env.DATABASE_PASSWORD)
: null
},
port: process.env.PORT || 8080
// if you're not using docker-compose for local development, this will default to 8080
// to prevent non-root permission problems with 80. Dockerfile is set to make this 80

View file

@ -0,0 +1,7 @@
const knex = require('knex');
const { database } = require('./config');
module.exports = knex({
client: 'mysql2',
connection: database,
});

View file

@ -12,13 +12,18 @@ const morgan = require("morgan");
// which is a best practice in Docker. Friends don't let friends code their apps to
// do app logging to files in containers.
const database = require("./database");
// Appi
const app = express();
app.use(morgan("common"));
app.get("/", function(req, res) {
res.json({ message: "Hello Docker World!" });
app.get("/", function(req, res, next) {
database.raw('select VERSION() version')
.then(([rows, columns]) => rows[0])
.then((row) => res.json({ message: `Hello from MySQL ${row.version}` }))
.catch(next);
});
app.get("/healthz", function(req, res) {