corrected routes
This commit is contained in:
parent
c7a3c06f60
commit
176ec8ce5a
@ -1,6 +1,12 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
|
||||||
|
const plantsRouter = require('./plants/getPlants');
|
||||||
|
const calendarRouter = require('./plants_calendar/index');
|
||||||
|
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const plantsRouter = require('express').Router();
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
|
||||||
router.use('/plants',plantsRouter)
|
router.use('/plants',plantsRouter)
|
||||||
|
router.use('/plants_calendar',calendarRouter)
|
||||||
|
@ -1,17 +1,29 @@
|
|||||||
|
const { exec } = require('child_process');
|
||||||
|
exec('npm list axios', (err, stdout, stderr) => {
|
||||||
|
if (stderr.includes('empty')) {
|
||||||
|
console.log('Installing axios...');
|
||||||
|
exec('npm install axios', (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Error installing axios:', error);
|
||||||
|
} else {
|
||||||
|
console.log('Axios installed successfully');
|
||||||
|
startApp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
startApp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function startApp() {
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
const plantsRouter = express.Router();
|
const plantsRouter = express.Router();
|
||||||
const app = express();
|
|
||||||
const port = process.env.PORT || 3000;
|
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const CONFIG = require('./config');
|
const CONFIG = require('./config');
|
||||||
const {config} = require("../../../bro.config");
|
|
||||||
app.use(cors());
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
plantsRouter.use(cors());
|
||||||
console.log(`Server is running on port ${port}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function getAccessToken() {
|
async function getAccessToken() {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@ -106,7 +118,6 @@ plantsRouter.get('/:id', async (req, res) => {
|
|||||||
const plantData = await fetchPlantData(plantId);
|
const plantData = await fetchPlantData(plantId);
|
||||||
|
|
||||||
if (plantData) {
|
if (plantData) {
|
||||||
// Construct a response based on the plantData structure
|
|
||||||
const detailedPlantData = {
|
const detailedPlantData = {
|
||||||
id: plantData.pid,
|
id: plantData.pid,
|
||||||
display_name: plantData.display_name,
|
display_name: plantData.display_name,
|
||||||
@ -130,4 +141,5 @@ plantsRouter.get('/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use('/plants', plantsRouter);
|
module.exports = plantsRouter;
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
|
|
||||||
const app = express();
|
const plantsRouter = express.Router()
|
||||||
const port = 5000;
|
|
||||||
|
|
||||||
app.use(cors());
|
|
||||||
|
|
||||||
const plants = [
|
const plants = [
|
||||||
{
|
{
|
||||||
@ -13,7 +10,6 @@ const plants = [
|
|||||||
frequency: 3,
|
frequency: 3,
|
||||||
startDate: "2024-10-09",
|
startDate: "2024-10-09",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Sunflower",
|
name: "Sunflower",
|
||||||
image: "https://avatars.mds.yandex.net/i?id=31da587c9aabc83ad3615023f91d7284781be06c-10701700-images-thumbs&n=13",
|
image: "https://avatars.mds.yandex.net/i?id=31da587c9aabc83ad3615023f91d7284781be06c-10701700-images-thumbs&n=13",
|
||||||
@ -22,6 +18,7 @@ const plants = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
const calculateWateringDates = (startDate, frequency) => {
|
const calculateWateringDates = (startDate, frequency) => {
|
||||||
const dates = [];
|
const dates = [];
|
||||||
const start = new Date(startDate);
|
const start = new Date(startDate);
|
||||||
@ -39,10 +36,8 @@ const plantsWithDates = plants.map(plant => ({
|
|||||||
wateringDates: calculateWateringDates(plant.startDate, plant.frequency),
|
wateringDates: calculateWateringDates(plant.startDate, plant.frequency),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.get('/api/plants', (req, res) => {
|
plantsWithDates.get('/api/plants', (req, res) => {
|
||||||
res.json(plantsWithDates);
|
res.json(plantsWithDates);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
module.exports = plantsRouter;
|
||||||
console.log(`Server running on http://localhost:${port}`);
|
|
||||||
});
|
|
@ -3,6 +3,7 @@ const router = express.Router()
|
|||||||
|
|
||||||
|
|
||||||
router.use('/enterfront', require('./enterfront/index'))
|
router.use('/enterfront', require('./enterfront/index'))
|
||||||
|
|
||||||
router.use('/ecliptica', require('./ecliptica/index'))
|
router.use('/ecliptica', require('./ecliptica/index'))
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
Loading…
Reference in New Issue
Block a user