Skip to content

Commit 3f05c5c

Browse files
committed
--update : ode-expressjs container
1 parent efd0c33 commit 3f05c5c

File tree

7 files changed

+443
-2
lines changed

7 files changed

+443
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

apparel/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node
2+
WORKDIR app
3+
RUN npm install -g nodemon
4+
COPY package.json .
5+
RUN npm install
6+
RUN mv /app/node_modules /node_modules
7+
COPY . .
8+
EXPOSE 80
9+
CMD [ "nodemon", "server" ]

apparel/database/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { Pool } = require('pg');
2+
const database = new Pool({ user: 'postgres', host: 'database' });
3+
module.exports = database;

apparel/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "apparel",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "nodemon server.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"express": "^4.16.2",
15+
"pg": "^7.4.1"
16+
}
17+
}

apparel/server.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const express = require('express');
2+
const database = require('./database');
3+
4+
const HOST = '0.0.0.0';
5+
const PORT = 80;
6+
const app = express();
7+
8+
// the root route
9+
app.get('/', (req, res) => {
10+
database.query('SELECT * FROM apparel', (error, response) => {
11+
if (error) {
12+
res.status(500);
13+
return res.json(error);
14+
}
15+
res.status(200);
16+
return res.json(response.rows);
17+
});
18+
});
19+
20+
// listen to the host
21+
app.listen(PORT, HOST);
22+
console.log(`Server running : ${HOST}:${PORT}`);

0 commit comments

Comments
 (0)