我的应用程序代码:
import express, {Express, Request, Response, Router} from 'express';
import dotenv from 'dotenv';
import ArtistRouter from './routes/artist_routes';
import infoRouter from './routes/info_router';
import bodyParser from 'body-parser';
//Autor: Yannick Hiltscher
dotenv.config();
const cors = require('cors');
const app: Express = express();
app.use(cors());
var BodyParser=require('body-parser')
app.use(ArtistRouter);
app.use(infoRouter);
app.use(bodyParser.json())
const port = process.env.PORT;
app.listen(port, () => {
console.log(`Server started at http://localhost:${port}`);
});
字符串
我的路由器:
ArtistRouter.post('/artist', async (request,response) => {
var Nation = request.body.Nation;
var GB = request.body.GB;
var FN= request.body.FN;
var LN=request.body.LN;
var Web=request.body.Website;
var Insta=request.body.Insta;
var Rating=request.body.Rating;
NewArtists(request, response, Nation, GB, FN, LN, Web, Insta, Rating);
型
我的下一个js代码:
const ArtistData = {
"Nation":"Australia",
"GB":"amogus",
"FN":"ei9fj",
"LN":"eifj",
"Website":"woi",
"Insta":"fij",
"Rating":"fjfj",
}
const API='http://localhost:8081/artist'
axios.post(API, ArtistData)
.then(response => {
console.log('New artist created:');
displaySuccessMessage("Artist created");
})
.catch(error => {
console.log(ArtistData)
console.error('Error creating artist:', error);
displaySuccessMessage('Error creating artist');
});
const A=1;
return A;
}
型
我希望我的下一个js程序给予几个变量给我的API,但我得到错误“跨源请求阻塞”
可悲的是,我不能让它工作,我不知道为什么。有人知道为什么我的NextJS服务器没有权限的职位要求?
1条答案
按热度按时间i86rm4rw1#
试试这个
字符串