You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varexpress=require('express');varpath=require('path');varfavicon=require('serve-favicon');varlogger=require('morgan');varcookieParser=require('cookie-parser');varbodyParser=require('body-parser');varcors=require('cors')require('./models/connect')// var index = require('./routes/index');// var users = require('./routes/users');varrouter=require('./routes/index')varapp=express();app.use(cors())// view engine setupapp.set('views',path.join(__dirname,'views'));app.set('view engine','ejs');// uncomment after placing your favicon in /public//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));app.use(logger('dev'));app.use(bodyParser.json());app.use(bodyParser.urlencoded({extended: false}));app.use(cookieParser());app.use(express.static(path.join(__dirname,'public')));// app.use('/', index);// app.use('/users', users);router(app)// catch 404 and forward to error handlerapp.use(function(req,res,next){varerr=newError('Not Found');err.status=404;next(err);});// error handlerapp.use(function(err,req,res,next){// set locals, only providing error in developmentres.locals.message=err.message;res.locals.error=req.app.get('env')==='development' ? err : {};// render the error pageres.status(err.status||500);res.render('error');});module.exports=app;
后端部分
需要跨域,以express为例使用cors插件
连接数据库 models/connect.js
数据模型 models/music.js
api接口路由 routes/index.js
修改app.js
完整app.js配置
前端部分
前端使用React,使用Fetch发送请求
获取所有数据
提交增加数据
查询数据
The text was updated successfully, but these errors were encountered: