POST http://localhost:5000/api/scan/start 400 (Bad Request)

Hi guys I am trying to make an audit web page and I want to test a scan using Openvas which I have hosted in a docker container, when I start the scan I get error Dashboard.js:13
**POST http://localhost:5000/api/scan/start 400 (Bad Request) My native language is Spanish, I apologize if there is a discrepancy in the translation.
**
in the frontend where I request scanning is Dashboard.js

import React, { useState } from 'react';
import './Dashboard.css';

function Dashboard() {
    const [target, setTarget] = useState('');
    const [configId, setConfigId] = useState('');
    const [scanId, setScanId] = useState('');
    const [status, setStatus] = useState('');
    const [report, setReport] = useState('');

    const startScan = async () => {
        try {
            const response = await fetch('http://localhost:5000/api/scan/start', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ target, configId }),
            });
            const data = await response.json();
            if (data.success) {
                setScanId(data.scanId);
            } else {
                alert(data.message);
            }
        } catch (error) {
            console.error('Error:', error);
        }
    };

    const checkStatus = async () => {
        try {
            const response = await fetch(`http://localhost:5000/api/scan/status/${scanId}`);
            const data = await response.json();
            setStatus(data.status);
        } catch (error) {
            console.error('Error:', error);
        }
    };

    const getReport = async () => {
        try {
            const response = await fetch(`http://localhost:5000/api/scan/report/${scanId}`);
            const data = await response.json();
            setReport(data.report);
        } catch (error) {
            console.error('Error:', error);
        }
    };

    return (
        <div className="dashboard-container">
            <h2>Dashboard</h2>
            <div className="form-group">
                <label>Target</label>
                <input
                    type="text"
                    value={target}
                    onChange={(e) => setTarget(e.target.value)}
                />
            </div>
            <div className="form-group">
                <label>Config ID</label>
                <input
                    type="text"
                    value={configId}
                    onChange={(e) => setConfigId(e.target.value)}
                />
            </div>
            <button onClick={startScan}>Start Scan</button>
            <div>
                <button onClick={checkStatus}>Check Status</button>
                <p>Status: <strong>{status}</strong></p>
            </div>
            <div>
                <button onClick={getReport}>Get Report</button>
                <p>Report: <strong>{report}</strong></p>
            </div>
        </div>
    );
}

export default Dashboard;

Backend

This is the docker-compose.yml file

version: '3'

services:
  openvas:
    image: mikesplain/openvas
    ports:
      - "443:443"
      - "9390:9390"
      - "9391:9391"
    environment:
      - PASSWORD=admin
    volumes:
      - openvas_data:/var/lib/openvas
      - openvas_logs:/var/log/openvas
      - openvas_etc:/etc/openvas

volumes:
  openvas_data:
  openvas_logs:
  openvas_etc:

The index.js is configured as follows:

require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser');
const userRoutes = require('./routes/userRoutes');
const scanRoutes = require('./routes/scanRoutes');

const app = express();
const PORT = process.env.PORT || 5000;

mongoose.connect(process.env.MONGODB_URI).then(() => {
    console.log('MongoDB connected');
}).catch((error) => {
    console.error('MongoDB connection error:', error);
});

app.use(cors());
app.use(bodyParser.json());
app.use('/api/users', userRoutes);
app.use('/api/scan', scanRoutes);

app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});

I have this scanRoutes.js file

const express = require('express');
const router = express.Router();
const { startScan, getScanStatus, getScanReport } = require('../controllers/scanController');

router.post('/start', startScan);
router.get('/status/:scanId', getScanStatus);
router.get('/report/:scanId', getScanReport);

module.exports = router;

I have this scanController.js file

const axios = require('axios');

// Configuración de Axios para OpenVAS
const openvasInstance = axios.create({
    baseURL: 'http://127.0.0.1:9390',
    timeout: 5000,
    headers: { 'Content-Type': 'application/json' },
});

exports.startScan = async (req, res) => {
    const { target } = req.body;
    if (!target) {
        return res.status(400).json({ success: false, message: 'Target is required' });
    }

    try {
        const response = await openvasInstance.post('/scan/start', { target });
        res.status(201).json({ success: true, scanId: response.data.scanId });
    } catch (error) {
        console.error('Error al iniciar escaneo:', error.message);
        res.status(500).json({ success: false, message: 'Failed to start scan' });
    }
};

exports.getScanStatus = async (req, res) => {
    const { scanId } = req.params;
    try {
        const response = await openvasInstance.get(`/scan/status/${scanId}`);
        res.status(200).json({ success: true, status: response.data.status });
    } catch (error) {
        console.error('Error al obtener estado del escaneo:', error.message);
        res.status(500).json({ success: false, message: 'Failed to get scan status' });
    }
};

exports.getScanReport = async (req, res) => {
    const { scanId } = req.params;
    try {
        const response = await openvasInstance.get(`/scan/report/${scanId}`);
        res.status(200).json({ success: true, report: response.data.report });
    } catch (error) {
        console.error('Error al obtener reporte del escaneo:', error.message);
        res.status(500).json({ success: false, message: 'Failed to get scan report' });
    }
};

I tried to try with another Openvas image but it didn’t work, I really can’t find logical errors in the code, that’s why I come here since I’m new to using web languages. I thank you in advance if you can tell me why it does not scan.

Note: My native language is Spanish, I apologize if there is a discrepancy in the translation.

New contributor

ESTIVEN DE MOYA SUAREZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật