#Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http:/

17 messages · Page 1 of 1 (latest)

ivory patrol
#
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)
#

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^^

old granite
#

Well, I seem you didn't user "cors" module.

#

Please use it and add the following code.

quasi rose
#

it seems that your server runs on localhost:5173 and you make your request to localhost:5000

hazy blaze
quasi rose
#

i dont really understand what you mean the db is running on 5000?

hazy blaze
#

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")
})
quasi rose
#

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