enables PUT requests on frontend
This commit is contained in:
@@ -10,7 +10,10 @@ const requests = {
|
||||
superagent.get(`${url}`).then(responseBody),
|
||||
|
||||
post: (url, body) =>
|
||||
superagent.post(`${url}`, body).then(responseBody)
|
||||
superagent.post(`${url}`, body).then(responseBody),
|
||||
|
||||
put: (url, body) =>
|
||||
superagent.put(`${url}`, body).then(responseBody)
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -19,7 +19,10 @@ const withEditData = (PassedComponent, collection, config) => {
|
||||
if (slug) {
|
||||
api.requests.get(`${config.serverUrl}/${collection.slug}/${slug}`).then(
|
||||
res => this.setState({ data: res }),
|
||||
err => console.warn(err)
|
||||
err => {
|
||||
console.warn(err);
|
||||
this.props.history.push('/not-found');
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { Component, createContext } from 'react';
|
||||
import { Input } from 'payload/components';
|
||||
import api from 'payload/api';
|
||||
|
||||
import './index.scss';
|
||||
@@ -119,11 +120,11 @@ class Form extends Component {
|
||||
|
||||
return (
|
||||
<form
|
||||
noValidate
|
||||
onSubmit={this.submit}
|
||||
method={this.props.method}
|
||||
action={this.props.action}
|
||||
className={this.props.className}>
|
||||
noValidate
|
||||
onSubmit={this.submit}
|
||||
method={this.props.method}
|
||||
action={this.props.action}
|
||||
className={this.props.className}>
|
||||
<Status />
|
||||
<FormContext.Provider value={{
|
||||
setValue: this.setValue.bind(this),
|
||||
|
||||
10
src/index.js
10
src/index.js
@@ -1,6 +1,7 @@
|
||||
const mongoose = require('mongoose');
|
||||
const passport = require('passport');
|
||||
const express = require('express');
|
||||
import mongoose from 'mongoose';
|
||||
import passport from 'passport';
|
||||
import express from 'express';
|
||||
import methodOverride from 'method-override';
|
||||
|
||||
module.exports = {
|
||||
init: options => {
|
||||
@@ -24,10 +25,13 @@ module.exports = {
|
||||
res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
|
||||
res.header('Access-Control-Allow-Headers',
|
||||
'Origin X-Requested-With, Content-Type, Accept');
|
||||
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
options.app.use(express.json());
|
||||
options.app.use(methodOverride('X-HTTP-Method-Override'))
|
||||
options.app.use(express.urlencoded({extended: true}));
|
||||
options.app.use(options.router);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user