Update API base URL to use REACT_APP_BACKEND_URL and include '/api' path

This commit is contained in:
2025-06-11 22:00:13 -03:00
parent 2f6eb4f6c1
commit 3de6609dc0
10 changed files with 546 additions and 706 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
# ---> Node # ---> Node
build
# Logs # Logs
logs logs
*.log *.log

View File

@@ -22,7 +22,8 @@
"@types/cors": "^2.8.10", "@types/cors": "^2.8.10",
"@types/express": "^4.17.8", "@types/express": "^4.17.8",
"@types/multer": "^1.4.5", "@types/multer": "^1.4.5",
"ts-node-dev": "^1.0.0", "ts-node": "^10.9.2",
"typescript": "^4.0.3" "ts-node-dev": "^2.0.0",
"typescript": "^5.8.3"
} }
} }

View File

@@ -3,7 +3,7 @@ import path from 'path';
export default { export default {
storage: multer.diskStorage({ storage: multer.diskStorage({
destination: path.join(__dirname, '..','..','uploads'), destination: path.join(process.cwd(), 'uploads'),
filename: (request, file, cb) => { filename: (request, file, cb) => {
const fileName = `${Date.now()}_${file.originalname}`; const fileName = `${Date.now()}_${file.originalname}`;

View File

@@ -16,6 +16,4 @@ routes.post('/orphanages', upload.array('images'), OrphanagesController.create);
routes.get('/orphanages', OrphanagesController.getAll); routes.get('/orphanages', OrphanagesController.getAll);
routes.get('/orphanages/:id', OrphanagesController.getIndex); routes.get('/orphanages/:id', OrphanagesController.getIndex);
export default routes; export default routes;

View File

@@ -4,7 +4,7 @@ import path from 'path';
import 'express-async-errors'; import 'express-async-errors';
import cors from 'cors'; import cors from 'cors';
import './database/connection'; // This line now automatically runs the connection import './database/connection';
import errorHandler from './errors/handler'; import errorHandler from './errors/handler';
import routes from './routes'; import routes from './routes';
@@ -12,11 +12,15 @@ const app = express();
app.use(cors()); app.use(cors());
app.use(express.json()); app.use(express.json());
app.use('/uploads', express.static(path.join(__dirname, '..', 'uploads')));
app.use('/api', routes);
const uploadsPath = path.join(process.cwd(), 'uploads');
app.use('/uploads', express.static(uploadsPath));
app.use(routes); app.use(routes);
app.use(errorHandler); app.use(errorHandler);
app.listen(process.env.PORT || 3101, () => { app.listen(process.env.PORT || 3101, () => {
console.log(`Serving static files for /uploads from: ${uploadsPath}`);
console.log('Server is running on http://localhost:' + (process.env.PORT || 3101)); console.log('Server is running on http://localhost:' + (process.env.PORT || 3101));
console.log('Environment:', process.env.NODE_ENV || 'development'); console.log('Environment:', process.env.NODE_ENV || 'development');
}); });

View File

@@ -5,7 +5,7 @@ export default {
render(image: Image) { render(image: Image) {
return { return {
id: image.id, id: image.id,
url: `${process.env.BACKEND_URL}/uploads/${image.path}` url: `${process.env.REACT_APP_BACKEND_URL}/uploads/${image.path}`
}; };
}, },

View File

@@ -1,6 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Visit https://aka.ms/tsconfig.json to read more about this file */
"outDir": "./dist",
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ // "incremental": true, /* Enable incremental compilation */

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
import axios from 'axios'; import axios from 'axios';
const api = axios.create({ const api = axios.create({
baseURL: process.env.BACKEND_URL || 'http://localhost:3101', baseURL: process.env.REACT_APP_BACKEND_URL || 'http://localhost:3101/api',
}); });
export default api; export default api;