Created
October 14, 2018 19:22
-
-
Save converge/072d770dca0c9389c377f80c2e145e9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ERROR: | |
WARNING in ./node_modules/express/lib/view.js 81:13-25 | |
Critical dependency: the request of a dependency is an expression | |
@ ./node_modules/express/lib/application.js | |
@ ./node_modules/express/lib/express.js | |
@ ./node_modules/express/index.js | |
@ ./app/services/api_mongo.js | |
@ ./app/src/components/Dashboard/index.jsx | |
@ ./app/src/renderer_process.js | |
# | |
# API_MONGO / REASTful | |
# | |
const mongoose = require('mongoose') | |
const express = require('express'), | |
app = express(), | |
port = 3000 | |
// mongoose connection | |
mongoose.Promise = global.Promise; | |
mongoose.connect('mongodb://localhost:27017/Tododb', {useNewUrlParser: true}) | |
// set and register route | |
const routes = require('./routes/testeRoutes') | |
routes(app) | |
app.listen(port) | |
// 404 | |
app.use(function(req, res) { | |
res.status(404).send({url: req.originalUrl + ' not found'}) | |
}) | |
console.log('RESTful API working on port: ' + port) | |
# | |
# REACTJS COMPONENT | |
# | |
import React, {Component, Fragment} from 'react' | |
import styles from './styles.css' | |
import {HashRouter as Router, Link} from 'react-router-dom' | |
import {PythonShell} from 'python-shell' | |
import api from '../../../services/api' | |
import api_mongo from '../../../services/api_mongo' | |
export default class Dashboard extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
data: [] | |
} | |
} | |
componentDidMount() { | |
this.loadProducts() | |
} | |
// -> this works, now I want to load data from api_mongo.js instead of (api.js that reads an online api) | |
loadProducts = async () => { | |
const response = await api.get('/products') | |
this.setState({ | |
data: response.data.docs | |
}) | |
console.log(response) | |
} | |
render() { | |
let rows = this.state.data.map(person => { | |
return <PersonRow key={person._id} data={person}/> | |
}) | |
return (<Fragment> | |
<div className={styles.dashboard}> | |
<h1>DASHBOARD lenght: {this.state.data.length}</h1> | |
<table> | |
<tbody> | |
<tr> | |
<td>id</td> | |
<td>title</td> | |
<td>url</td> | |
<td>created at</td> | |
</tr> | |
{rows} | |
</tbody> | |
</table> | |
<button>test</button> | |
</div> | |
</Fragment>) | |
} | |
} | |
const PersonRow = (props) => { | |
return (<tr> | |
<td> | |
{props.data._id} | |
</td> | |
<td> | |
{props.data.title} | |
</td> | |
<td> | |
{props.data.url} | |
</td> | |
<td> | |
{props.data.createdAt} | |
</td> | |
</tr>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment