Added backend+database support
This commit is contained in:
parent
663b83b361
commit
f39baae69b
|
@ -1,23 +1,27 @@
|
||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
webmarker/node_modules
|
||||||
|
webmarker/..pnp
|
||||||
|
webmarker/.pnp.js
|
||||||
|
webmarker/coverage
|
||||||
|
webmarker/build
|
||||||
|
webmarker/.DS_Store
|
||||||
|
webmarker/.env.local
|
||||||
|
webmarker/.env.development.local
|
||||||
|
webmarker/.env.test.local
|
||||||
|
webmarker/.env.production.local
|
||||||
|
webmarker/npm-debug.log*
|
||||||
|
webmarker/yarn-debug.log*
|
||||||
|
webmarker/yarn-error.log*
|
||||||
|
|
||||||
# dependencies
|
webmarker_backend/node_modules
|
||||||
/node_modules
|
webmarker_backend/..pnp
|
||||||
/.pnp
|
webmarker_backend/.pnp.js
|
||||||
.pnp.js
|
webmarker_backend/coverage
|
||||||
|
webmarker_backend/build
|
||||||
# testing
|
webmarker_backend/.DS_Store
|
||||||
/coverage
|
webmarker_backend/.env.local
|
||||||
|
webmarker_backend/.env.development.local
|
||||||
# production
|
webmarker_backend/.env.test.local
|
||||||
/build
|
webmarker_backend/.env.production.local
|
||||||
|
webmarker_backend/npm-debug.log*
|
||||||
# misc
|
webmarker_backend/yarn-debug.log*
|
||||||
.DS_Store
|
webmarker_backend/yarn-error.log*
|
||||||
.env.local
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
|
@ -34,5 +34,6 @@
|
||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"proxy": "http://localhost:3001/"
|
||||||
}
|
}
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
|
@ -1,4 +1,5 @@
|
||||||
.App {
|
.App {
|
||||||
|
min-height: 96vh;
|
||||||
padding: 2vh;
|
padding: 2vh;
|
||||||
background-color: #1f2c38;
|
background-color: #1f2c38;
|
||||||
color: white;
|
color: white;
|
||||||
|
@ -43,6 +44,7 @@ textarea:focus, input:focus{
|
||||||
.material-icons-outlined.md-36 { font-size: 36px; }
|
.material-icons-outlined.md-36 { font-size: 36px; }
|
||||||
|
|
||||||
.table {
|
.table {
|
||||||
|
width: 100%;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
|
@ -56,3 +58,7 @@ textarea:focus, input:focus{
|
||||||
font-size: 1.6rem;
|
font-size: 1.6rem;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table tbody tr:nth-of-type(2n-1) {
|
||||||
|
background-color:#273949;
|
||||||
|
}
|
|
@ -7,9 +7,9 @@ function App() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const res = await fetch('https://api.github.com/users');
|
const res = await fetch('/get');
|
||||||
const resJSON = await res.json();
|
const resJSON = await res.json();
|
||||||
// data.sort((b, a) => new Date(b.Date) - new Date(a.Date)) // Sort by date
|
console.log(resJSON)
|
||||||
setData(resJSON);
|
setData(resJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,4 +29,23 @@ function App() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
|
// fetch("/post", {
|
||||||
|
|
||||||
|
// // Adding method type
|
||||||
|
// method: "POST",
|
||||||
|
|
||||||
|
// // Adding body or contents to send
|
||||||
|
// body: JSON.stringify({
|
||||||
|
// name: "foo",
|
||||||
|
// title: "bar",
|
||||||
|
// link: liveinternet.ru,
|
||||||
|
// tag: Red
|
||||||
|
// }),
|
||||||
|
|
||||||
|
// // Adding headers to the request
|
||||||
|
// headers: {
|
||||||
|
// "Content-type": "application/json; charset=UTF-8"
|
||||||
|
// }
|
||||||
|
// });
|
|
@ -9,15 +9,17 @@ const List = ({data}) => {
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Title</th>
|
<th>Title</th>
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
|
<th>Tag</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{data.map((e, i) => {
|
{data.map((e, i) => {
|
||||||
return <tr key={i}>
|
return <tr key={i}>
|
||||||
<td>{i + 1}</td>
|
<td>{i + 1}</td>
|
||||||
<td>{e.login}</td>
|
<td>{e.name}</td>
|
||||||
<td>{e.node_id}</td>
|
<td>{e.title}</td>
|
||||||
<td>{e.html_url}</td>
|
<td>{e.link}</td>
|
||||||
|
<td>{e.tag}</td>
|
||||||
</tr>
|
</tr>
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"name": "webmarker_backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "The backend",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.17.3",
|
||||||
|
"mongodb": "^4.5.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const { MongoClient } = require('mongodb');
|
||||||
|
const port = process.env.PORT || 3001;
|
||||||
|
|
||||||
|
const uri = "mongodb://localhost:27017";
|
||||||
|
|
||||||
|
const client = new MongoClient(uri);
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.get('/get', async (req, res) => {
|
||||||
|
const data = await getDoc();
|
||||||
|
res.send(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/post', (req, res) => {
|
||||||
|
// insertDoc(req.body);
|
||||||
|
console.log(req.body)
|
||||||
|
});
|
||||||
|
|
||||||
|
async function insertDoc(doc) {
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
const database = client.db("sample_db");
|
||||||
|
const list = database.collection("list");
|
||||||
|
const result = await list.insertOne(doc);
|
||||||
|
|
||||||
|
console.log('DONE');
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
finally {
|
||||||
|
await client.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDoc() {
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
const database = client.db("sample_db");
|
||||||
|
const list = database.collection("list");
|
||||||
|
const result = await list.find({}).toArray();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
finally {
|
||||||
|
await client.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Success! running on port ${port}.`);
|
||||||
|
});
|
Ŝarĝante…
Reference in New Issue