Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artworks fetch #122

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile backend
FROM node:16.14
FROM node:lts-alpine

WORKDIR /usr/src/app

Expand Down
27 changes: 13 additions & 14 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ app.use(express.json());
app.use(express.static("public"));

// Import the API routes from the router module
const path = require("path");
const router = require("./router");

// Mount the API routes under the "/api" endpoint
Expand Down Expand Up @@ -113,22 +114,20 @@ app.use(express.static(reactBuildPath));

// Redirect unhandled requests to the react index file

app.get("*", (req, res) => {
res.sendFile(`${reactBuildPath}/index.html`);
});

// const path = require("path");

// app.use("*", (req, res) => {
// if (req.originalUrl.includes("assets")) {
// res.sendFile(
// path.resolve(__dirname, `../../frontend/dist/${req.originalUrl}`)
// );
// } else {
// res.sendFile(path.resolve(__dirname, `../../frontend/dist/index.html`));
// }
// app.get("*", (req, res) => {
// res.sendFile(`${reactBuildPath}/index.html`);
// });

app.use("*", (req, res) => {
if (req.originalUrl.includes("assets")) {
res.sendFile(
path.resolve(__dirname, `../../frontend/dist/${req.originalUrl}`)
);
} else {
res.sendFile(path.resolve(__dirname, `../../frontend/dist/index.html`));
}
});

/* ************************************************************************* */

// Middleware for Error Logging (Uncomment to enable)
Expand Down
6 changes: 5 additions & 1 deletion backend/src/models/CaptureManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class CaptureManager extends AbstractManager {
}

async readAll() {
const [rows] = await this.database.query(`SELECT * FROM ${this.table}`);
const [rows] = await this.database.query(`
SELECT c.id, c.user_id, c.artwork_id, c.capture, a.picture AS artwork_url
FROM ${this.table} c
LEFT JOIN artworks a ON c.artwork_id = a.id
`);
return rows;
}

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
DB_USER: ${USER_NAME}
DB_PASSWORD: ${USER_PASSWORD}
DB_NAME: ${DB_NAME}
VITE_BACKEND_URL: ""
networks:
- proxy
labels:
Expand All @@ -30,4 +31,4 @@ services:

networks:
proxy:
external: true
external: true
2 changes: 1 addition & 1 deletion frontend/src/components/CaptureAdmin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function CaptureAdmin() {
<img
alt="Street Art"
className="original-img-grid"
src={artwork.picture}
src={artwork.artwork_url}
/>
<p className="original-work-grid">Oeuvre Originale</p>
</div>
Expand Down
Loading