Vuejs 无法在 Cpanel 上接收来自 Node 的响应

编程入门 行业动态 更新时间:2024-10-03 17:20:21

<a href=https://www.elefans.com/category/jswz/34/1759356.html style=Vuejs 无法在 Cpanel 上接收来自 Node 的响应"/>

Vuejs 无法在 Cpanel 上接收来自 Node 的响应

我已经在 Cpanel 上部署了我的 Nodejs 服务器,我尝试从我的 vuejs 前端(部署在同一个 cpanel 上)进行 API 调用

我有一个从 vuejs 到 nodejs 的发布请求和获取请求,它们在我对邮递员所做的测试中都工作正常,但如果我从 vue 发出请求,我只能在获取请求时得到响应并在发布请求时得到错误 500。

下面是我从vuejs发出的帖子请求

 async postTest() {
      console.log("test 1");
      const response = await ManagementService.postTest({
        data: "123",
      });
      console.log("test 2");
      console.log(response.data);
      console.log("test 3");

下面是我的 API 设置 (Api.js)

import axios from "axios";

export default () => {
  return axios.create({
    baseURL: "",
  });
};
import Api from "./Api";

export default {
  postTest(data) {
    return Api().post("postTest", data);
  },
  getTest() {
    return Api().get("apiTest");
  },
};

这是我的 nodejs API,用于接收发布请求并发回响应。

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path');
const multer = require('multer');
// const sql = require('./src/mysql_connection');
const app = express();
app.use(bodyParser.json());
app.use(cors({
    origin: "*",
}));

if(process.env.NODE_ENV === 'production') {
    app.use(express.static(__dirname + '/public'));
  app.get(/.*/, (req, res) => {
    res.sendFile(__dirname + '/public/index.html');
  });
}

app.post('/postTest', (req, res) => {
    res.json(req.body);
})

app.get('/', (req, res) => {
    res.send('it Works !');
})


app.listen();
回答如下:

更多推荐

Vuejs 无法在 Cpanel 上接收来自 Node 的响应

本文发布于:2024-05-30 04:28:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770161.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Vuejs   Cpanel   Node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!