logicp 6 anos atrás
pai
commit
06d0bc96df
5 arquivos alterados com 139 adições e 515 exclusões
  1. 11 4
      package.json
  2. 8 0
      src/App.js
  3. 65 0
      src/server/index.js
  4. BIN
      xmas.sqlite
  5. 55 511
      yarn.lock

+ 11 - 4
package.json

@@ -4,16 +4,23 @@
   "private": true,
   "dependencies": {
     "@material-ui/core": "^3.4.0",
-    "loopback-cli": "^4.2.1",
-    "loopback-connector-postgresql": "^3.5.0",
+    "body-parser": "^1.18.3",
+    "cors": "^2.8.5",
+    "express": "^4.16.4",
+    "nodemon": "^1.18.6",
+    "npm-run-all": "^4.1.3",
     "react": "^16.6.1",
     "react-dom": "^16.6.1",
     "react-icons": "^3.2.2",
     "react-scripts": "2.1.1",
-    "sequelize": "^4.41.1"
+    "sequelize": "^4.41.1",
+    "sqlite3": "^4.0.4"
   },
   "scripts": {
-    "start": "react-scripts start",
+    "start": "npm-run-all --parallel watch:server start:web",
+    "start:web": "react-scripts start",
+    "start:server": "node src/server",
+    "watch:server": "nodemon --watch src/server src/server",
     "build": "react-scripts build",
     "test": "react-scripts test",
     "eject": "react-scripts eject"

+ 8 - 0
src/App.js

@@ -4,6 +4,7 @@ import './App.css';
 import { MdWarning as WarningIcon } from 'react-icons/md'
 import { TiTree as TreeIcon } from 'react-icons/ti'
 import { FaSmileWink as WinkEmoji } from 'react-icons/fa'
+import { Button } from '@material-ui/core'
 
 const styles = {
   row: {
@@ -44,6 +45,12 @@ const styles = {
 
 class App extends Component {
 
+  testClick = async () => {
+    await fetch('http://localhost:3002/test', {
+      method: 'POST',
+      body: { test: 'test body' }
+    })
+  }
 
   render() {
     return (
@@ -135,6 +142,7 @@ class App extends Component {
             <TreeIcon style={styles.spin}/> <TreeIcon style={styles.spin}/> <TreeIcon style={styles.spin}/>
           </span>
         </aside>
+        <Button onClick={this.testClick}> TEST </Button>
       </div>
     );
   }

+ 65 - 0
src/server/index.js

@@ -0,0 +1,65 @@
+const Sequelize = require('sequelize');
+const express = require("express");
+const bodyParser = require("body-parser");
+require('dotenv').config({ path: '.env.local' });
+
+const database = new Sequelize({
+  dialect: 'sqlite',
+  storage: './xmas.sqlite',
+});
+
+const Attendee = database.define('attendee', {
+  name: Sequelize.STRING,
+  guest: Sequelize.BOOLEAN,
+});
+
+class App {
+    //Run configuration methods on the Express instance.
+    constructor() {
+        this.express = express();
+        this.middleware();
+        this.routes();
+    }
+    // Configure Express middleware.
+    middleware() {
+        // this.express.use(logger('dev'));
+        this.express.use(bodyParser.json());
+        this.express.use(bodyParser.urlencoded({ extended: false }));
+        // this.express.engine('html', require('ejs').renderFile);
+    }
+    // Configure API endpoints.
+    routes() {
+        /* This is just to get up and running, and to make sure what we've got is
+         * working so far. This function will change when we start to add more
+         * API endpoints */
+        this.express.get('/test', (req, res) => {
+          console.log(req)
+          res.json({response: 'yo mamma'})
+        })
+
+        this.express.post('/attendee', (req, res) => {
+          console.log(req.body)
+          // Attendee.findOrCreate({ name: 'Emmanuel', guest: true }).then(() =>
+          Attendee.findOrCreate({
+            where: {
+              name: 'Emmanuel'
+            }, defaults: {name: 'Emmanuel', guest: true}
+          })
+          .spread((param1, param2) => {
+            console.log('Param 1')
+            console.log(param1)
+            console.log('Param 2')
+            console.log(param2)
+          })
+          res.json({response: 'yeah we got you'})
+        })
+    }
+}
+
+const app = new App().express
+app.listen(3002)
+
+
+database.sync().then(() => {
+    console.log(`Listening on port ${3002}`);
+});

BIN
xmas.sqlite


Diferenças do arquivo suprimidas por serem muito extensas
+ 55 - 511
yarn.lock


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff