Добрый день, перепробовал всё, но данные из сервер axios не приходят на express:
Backend:
const express = require('express');
//solve cors issue
const cors = require("cors");
const app = express();
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.use(cors());
const port = 5000;
const Pool = require('pg').Pool;
//Enter here your Postres database details
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: '1231',
dialect: 'postgres',
port: 5432
});
//Database connection and also please create postgres database first
pool.connect((err, client, release) => {
if (err) {
return console.error(
'Error acquiring client', err.stack)
}
client.query('SELECT NOW()', (err, result) => {
release()
if (err) {
return console.error(
'Error executing query', err.stack)
}
console.log("Connected to Database !")
})
})
let test1 = '';
let test2 = '';
app.post('/tutorials', (req,res,next) => {
test1 = req.query;
console.log(req.query);
})
Frontend:
import axios from 'axios'
export default {
data(){
return {
auth: false,
login: '',
password: ''
}
},
methods: {
sendDate() {
axios
.get('http://localhost:5000/tutorials', (resp) => {
resp.send(this.data.login)
})