Как отправлять из textarea html-код в базу данных mongodb?

// Это код который отправляет данные на сервер и сохраняет их в базе данных
async function sendToServer() {
        const requestOptions = {
            method: 'POST',
            body: JSON.stringify({ ...form }),
            headers: {
                'Accept': 'application/json, text/html, */*',
                'Content-Type': 'application/json',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS"
            }
        };

        const url = 'http://localhost:5000/api/news/add'

        await fetch(url, requestOptions)
            .then(res => res.json())
            .then(res => alert('Новость успешно создана!'))
            .catch(e => {
                console.log(e)
            })

        return setForm({
            title: '',
            image: '',
            descr: '',
            shortDescr: '',
            date: ''
        })
    }


// Это код модели в mongodb
const newsSchema = new Schema({
    title: {
        type: String,
        default: 'Новость'
    },
    shortDescr: {
        type: String,
        required: true
    },
    descr: {
        type: String,
        required: true
    },
    image: {
        type: String,
        default: 'https://static8.depositphotos.com/1338574/829/i/600/depositphotos_8292496-stock-photo-news.jpg'
    },
    date: {
        type: String
    },
    // imageDescr: {
    //     type: Array,
    // }
})


Когда я пишу в textarea (<b>Жирный шрифт</b>) у меня эту строку сохраняет в базе данных и так же выводит с тэгами на странице с этими данными
  • Вопрос задан
  • 69 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы