Added config file
This commit is contained in:
+3
-1
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
|
||||
import './styles/App.css';
|
||||
import List from './componets/List';
|
||||
import AddModal from './componets/AddModal';
|
||||
import config from './config.json';
|
||||
|
||||
function App() {
|
||||
const [data, setData] = useState([]);
|
||||
@@ -22,7 +23,8 @@ function App() {
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
const res = await fetch('/get');
|
||||
const address = config.client.api_address + ":" + config.server.port;
|
||||
const res = await fetch(address + '/get');
|
||||
const resJSON = await res.json();
|
||||
const Data = resJSON.sort((a, b) => { return b-a });
|
||||
setData(Data);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import '../styles/Modal.css';
|
||||
import config from '../config.json';
|
||||
|
||||
const AddModal = ({onExit}) => {
|
||||
const [name, setName] = useState('');
|
||||
@@ -32,7 +33,8 @@ const AddModal = ({onExit}) => {
|
||||
}
|
||||
|
||||
if(name != '' && isValidHttpUrl(link) && tag != '') {
|
||||
fetch("/post", {
|
||||
const address = config.client.api_address + ":" + config.server.port;
|
||||
fetch(address + "/post", {
|
||||
|
||||
// Adding method type
|
||||
method: "POST",
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import '../styles/List.css';
|
||||
import config from '../config.json';
|
||||
|
||||
const List = ({data}) => {
|
||||
function deleteEntity(id) {
|
||||
fetch("/delete", {
|
||||
const address = config.client.api_address + ":" + config.server.port;
|
||||
fetch(address + "/delete", {
|
||||
|
||||
// Adding method type
|
||||
method: "DELETE",
|
||||
@@ -12,7 +14,7 @@ const List = ({data}) => {
|
||||
|
||||
// Adding headers to the request
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
}
|
||||
})
|
||||
.then(res => res.text())
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"client": {
|
||||
"api_address": "http://localhost"
|
||||
},
|
||||
"server": {
|
||||
"port": 5000,
|
||||
"mongodb_full_address": "mongodb://localhost:27017"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user