diff --git a/backend/app.js b/backend/app.js index 04696a6606fce737b31a08a6630902bdcff30311..279a8a5679afa855db7bdfc3245cb80ffa50b8b3 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 d94ea2b731c5777b76d4ae672695ae6593e61bc5..b0516a41fd4a72ac6e1eec3bf7f25a9305f533de 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 308235de5ff023f36cf39d49fbf9e4c9b92807e1..88e71603bf6142f908181e616b0eab6c11476748 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 0000000000000000000000000000000000000000..ad6ff9d24a40190ee3b520592184026afe8bf9d1 --- /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 0a672274513386d8cac48c18679308bcc402a7e8..ea77ae2a12f4e6d349b1dda612a0326ed13fc88f 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 65edda6796aac9cf26d31f0335f071d4ca5e553b..dd30de63b22148b41245a86b550c2a6988e59a34 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 e0e936788ff689f5432248fdd6d24e7a4c21066a..2b8074ea0a0d446a765c6a64f76f530750144393 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 22357718db1096885980b0fcbaa98bbbbd0f625a..7780444684c80762d30265de68a76a7e2e715dca 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 0509569010bea2cb3602d40835f38c25289ac4f6..f3fc542471bc0fc6b24a42bd0e003a0898e5ae5a 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=