今天需要在我的服务器(本地)中使用base64图像的帖子返回此错误: 前端正在使用AngularJS 后端使用MongoDB,Node.JS,Mongoose和NodeRestFULL
这是我的server.js
const express = require('express')
const server = express();
//transform params to int
const queryParser = require('express-query-int')
//const allowCors = require('./cors')
server.use(function(req,res,next){
res.header('Access-Control-Allow-Origin','*')
res.header('Access-Control-Allow-Methods','GET,POST,OPTIONS,PUT,PATCH,DELETE')
res.header('Access-Control-Allow-Headers','Origin, X-Requested-With, Content-Type, Accept')
res.header('Access-Control-Allow-Credentials', true);
next()
})
server.use(queryParser())
server.use(bodyParse.text({type:'*/*'}))
server.use(bodyParse.urlencoded({limit: '50mb', extended: true}))
server.use(bodyParse.json({type:'json/*', limit: '50mb'}))
//server.use(bodyParse.urlencoded({limit: '50mb'}));
server.listen(port, function(){
console.log(`BACKEND está rodando na porta ${port}`)
})
module.exports = server
loader.js
const server = require('./config/server')
require('./config/database')
require('./config/routes')(server)
这是我的mongodb架构
const restful = require('node-restful')
const mongoose = restful.mongoose
//Schema para os comprovantes
const reciboProventoSchema = new mongoose.Schema({
name: { type: String, required: true},
month: { type: String, required: true},
description: { type: String, required: true},
imgBase: {type: String, required: true}
})
module.exports = restful.model('BillsPaysProv', reciboProventoSchema)
在这里,我将提供基本服务
//Import schemas
const BillsPaysProv = require('./billsProv')
//Create service to post a mensage contact
BillsPaysProv.methods(['get','put','post','delete'])
BillsPaysProv.updateOptions({new: true, runValidators: true})
module.exports = BillsPaysProv