import mysql from 'mysql2'
import dotenv from 'dotenv'
dotenv.config()
const pool = mysql.createPool({
host: process.env.MY_SQL_HOST,
user: process.env.MY_SQL_USER,
password: process.env.MY_SQL_PASSWORD,
database: process.env.MY_SQL_DATABASE
}).promise()
export async function getPBTasks() {
const [rows] = await pool.query("SELECT * FROM product_backlog_tasks")
console.log(rows)
}
export async function getPBTask(id) {
const [rows] = await pool.query(`
SELECT *
FROM product_backlog_tasks
WHERE id = ?
`, [id])
return rows[0]
}
export async function createPBTask(
taskName,
description,
storyPoints,
priorityRating,
tags,
assign,
taskStatus,
taskStage
) {
const result = await pool.query(`
INSERT INTO product_backlog_tasks (
taskName,
description,
storyPoints,
priorityRating,
tags,
assign,
taskStatus,
taskStage
)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)
`, [
taskName,
description,
storyPoints,
priorityRating,
tags,
assign,
taskStatus,
taskStage
])
const id = result.insertId
return getPBTask(id)
}
const result = await createPBTask('Create a table', 'Create a table with HTML', 5, 'Urgent', 'Frontend', 'None', 'Active', 'Development')
console.log(result)
#Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http:/
17 messages · Page 1 of 1 (latest)
database.js ^^
import express from 'express'
import { getPBTasks, getPBTask, createPBTask } from './database.js'
import cors from 'cors'
const app = express()
app.use(express.json())
app.use(cors({
origin: 'http://localhost:5173', // Replace this with the actual port your frontend runs on
}));
app.post("/tasks", async (req, res) => {
const { taskName,
description,
storyPoints,
priorityRating,
tags,
assign,
taskStatus,
taskStage } = req.body
const task = await createPBTask(taskName,
description,
storyPoints,
priorityRating,
tags,
assign,
taskStatus,
taskStage)
res.send(task)
})
app.get("/tasks", async (req, res) => {
const tasks = await getPBTasks()
res.send(tasks)
})
app.listen(5000, () => {
console.log("Server is running on port 5000")
})
App.js^^
the JSX file that fetches^^
Well, I seem you didn't user "cors" module.
Please use it and add the following code.
it seems that your server runs on localhost:5173 and you make your request to localhost:5000
i think frontend is running on port 5173 and backend on port 5000
i dont really understand what you mean the db is running on 5000?
if you see the last lines of code of the App.js file
the backend is running on port 5000
app.listen(5000, () => {
console.log("Server is running on port 5000")
})
i see, i hadnt noticed that line, i just look at the
app.use(cors({
origin: 'http://localhost:5173', // Replace this with the actual port your frontend runs on
}));
im not familiar at all with express itself, just node