当前位置: 代码迷 >> 综合 >> node.js cors
  详细解决方案

node.js cors

热度:26   发布时间:2023-12-05 01:24:45.0

安装

npm install cors -S

配置

在app.js文件中配置cors

var cors=require('cors')

app.use(cors())

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors=require('cors')var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');var app = express();app.use(cors())
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

  相关解决方案