From 1e67be7ba8ad7fa2afcc9f59e32b056646ea5bd6 Mon Sep 17 00:00:00 2001
From: Damien <damien.armillon@gmail.com>
Date: Sat, 4 May 2019 17:13:29 +0200
Subject: [PATCH] Premiere tentative pour changer proxy

---
 backend/app.js                 |  3 ++-
 backend/routes/routesToucan.js |  2 +-
 front/package.json             |  3 ++-
 front/src/.gitignore           |  1 +
 front/src/App.js               |  2 +-
 front/src/FormToucan.js        | 14 +++++++++++---
 front/src/ToucanLine.js        |  5 +++--
 front/src/ToucanTable.js       | 12 ++++++++----
 front/yarn.lock                | 12 ++++++++++--
 9 files changed, 39 insertions(+), 15 deletions(-)
 create mode 100644 front/src/.gitignore

diff --git a/backend/app.js b/backend/app.js
index 04696a6..279a8a5 100644
--- a/backend/app.js
+++ b/backend/app.js
@@ -1,6 +1,7 @@
 var express = require("express");
 var bodyParser = require("body-parser");
 var mongoose = require("mongoose");
+var cors = require("cors");
 var routesToucan = require("./routes/routesToucan");
 
 var app = express();
@@ -13,7 +14,7 @@ db.on("error", console.error.bind(console, "connection error:"));
 db.once("open", function() {
     console.log("on est connecté!");
 });
-
+app.use(cors());
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({extended: true}));
 app.use("/toucan",routesToucan);
diff --git a/backend/routes/routesToucan.js b/backend/routes/routesToucan.js
index d94ea2b..b0516a4 100644
--- a/backend/routes/routesToucan.js
+++ b/backend/routes/routesToucan.js
@@ -19,7 +19,7 @@ router.route("/toucans")
                 if (err) {
                     res.send(err);
                 } else {
-                    res.json(toucans);
+                    res/*.header("Access-Control-Allow-Origin","*")*/.json(toucans);
                 }
             });
     })
diff --git a/front/package.json b/front/package.json
index 308235d..88e7160 100644
--- a/front/package.json
+++ b/front/package.json
@@ -2,8 +2,9 @@
   "name": "front",
   "version": "0.1.0",
   "private": true,
-  "proxy": "http://localhost:8000/",
   "dependencies": {
+    "cors": "^2.8.5",
+    "eslint": "^5.16.0",
     "react": "^16.8.6",
     "react-dom": "^16.8.6",
     "react-scripts": "3.0.0",
diff --git a/front/src/.gitignore b/front/src/.gitignore
new file mode 100644
index 0000000..ad6ff9d
--- /dev/null
+++ b/front/src/.gitignore
@@ -0,0 +1 @@
+.env.json
\ No newline at end of file
diff --git a/front/src/App.js b/front/src/App.js
index 0a67227..ea77ae2 100644
--- a/front/src/App.js
+++ b/front/src/App.js
@@ -8,7 +8,7 @@ function App() {
   return (
     <div>
     <Segment padded style={{margin:"3%"}}>
-      <FormToucan />
+  {/*<FormToucan /> */}
     </Segment>
     <Segment textAlign="center" padded style={{margin:"3%"}}>
       <ToucanTable/>
diff --git a/front/src/FormToucan.js b/front/src/FormToucan.js
index 65edda6..dd30de6 100644
--- a/front/src/FormToucan.js
+++ b/front/src/FormToucan.js
@@ -1,6 +1,7 @@
 import React, {Component} from 'react'
 import {Form, Message} from 'semantic-ui-react'
 import {DateInput} from 'semantic-ui-calendar-react'
+import 'moment/locale/fr'
 
 
 class FormToucan extends Component {
@@ -40,12 +41,16 @@ class FormToucan extends Component {
 
     }
 
-    onFileChange = (e) =>{
-        const file = e.target.files[0]
-        const name = e.target.name
+    onFileChange = (event) => {
+        const file = event.target.files[0]
+        const name = event.target.name
         this.setState({[name]: file})
     }
 
+    onDateChange = (event,{name,value}) =>{ 
+        
+    }
+
     onSubmit = () => {
         console.log(this.state)
     }
@@ -90,6 +95,9 @@ class FormToucan extends Component {
                 />
                 <DateInput
                     label="Date"
+                    localization="fr"
+                    name="date"
+                    value={this.state.date}
                     //required
                 />
 
diff --git a/front/src/ToucanLine.js b/front/src/ToucanLine.js
index e0e9367..2b8074e 100644
--- a/front/src/ToucanLine.js
+++ b/front/src/ToucanLine.js
@@ -1,6 +1,7 @@
 import React, {Component} from 'react'
 import {Table, Image, Button} from 'semantic-ui-react'
 import ModalSuppression from './ModalSuppression'
+import env from './.env'
 
 class ToucanLine extends Component {
     constructor(props) {
@@ -26,9 +27,9 @@ class ToucanLine extends Component {
         return (
             <Table.Row>
                 <Table.Cell >
-                    <a href={`http://localhost:8000/toucan/pdf/${this.props.toucan["_id"]}`}>
+                    <a href={`${env.backURL}/toucan/pdf/${this.props.toucan["_id"]}`}>
                     <Image
-                    src={`/toucan/img/${this.props.toucan["_id"]}`}
+                    src={`${env.backURL}/toucan/img/${this.props.toucan["_id"]}`}
                     size="small"
                     />
                     </a>
diff --git a/front/src/ToucanTable.js b/front/src/ToucanTable.js
index 2235771..7780444 100644
--- a/front/src/ToucanTable.js
+++ b/front/src/ToucanTable.js
@@ -1,6 +1,7 @@
 import React, {Component} from 'react'
 import {Table} from 'semantic-ui-react'
 import ToucanLine from './ToucanLine'
+import env from './.env'
 
 class ToucanTable extends Component{
     constructor(){
@@ -11,13 +12,16 @@ class ToucanTable extends Component{
     }
 
     componentDidMount(){
-        fetch('/toucan/toucans')
+        fetch(`${env.backURL}/toucan/toucans`)
         .then(result => {
-            result.json()
-            .then(toucans => {
+            console.log(result)
+            return result.json()
+        })
+        .then(toucans => {
+                console.log(toucans)
                 this.setState({toucans})
             })
-        })
+        .catch(err => console.log(err))
     }
 
     render() {
diff --git a/front/yarn.lock b/front/yarn.lock
index 0509569..f3fc542 100644
--- a/front/yarn.lock
+++ b/front/yarn.lock
@@ -2655,6 +2655,14 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
   resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
   integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
 
+cors@^2.8.5:
+  version "2.8.5"
+  resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
+  integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
+  dependencies:
+    object-assign "^4"
+    vary "^1"
+
 cosmiconfig@^4.0.0:
   version "4.0.0"
   resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
@@ -6447,7 +6455,7 @@ oauth-sign@~0.9.0:
   resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
   integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
 
-object-assign@4.1.1, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
+object-assign@4.1.1, object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
   version "4.1.1"
   resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
   integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
@@ -9484,7 +9492,7 @@ validate-npm-package-license@^3.0.1:
     spdx-correct "^3.0.0"
     spdx-expression-parse "^3.0.0"
 
-vary@~1.1.2:
+vary@^1, vary@~1.1.2:
   version "1.1.2"
   resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
   integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
-- 
GitLab