support ping and redirect

This commit is contained in:
c9s 2021-02-04 20:21:16 +08:00
parent 621321f5db
commit 237c621182
2 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,12 @@ import axios from "axios";
const baseURL = process.env.NODE_ENV === "development" ? "http://localhost:8080" : ""
export function ping(cb) {
return axios.get(baseURL + '/api/ping').then(response => {
cb(response.data)
});
}
export function testDatabaseConnection(dsn, cb) {
return axios.post(baseURL + '/api/setup/test-db', {dsn: dsn}).then(response => {
cb(response.data)
@ -20,6 +26,12 @@ export function saveConfig(cb) {
});
}
export function setupRestart(cb) {
return axios.post(baseURL + '/api/setup/restart').then(response => {
cb(response.data)
});
}
export function addSession(session, cb) {
return axios.post(baseURL + '/api/sessions', session).then(response => {
cb(response.data)

View File

@ -1,4 +1,7 @@
import React from 'react';
import { useRouter } from 'next/router';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import List from '@material-ui/core/List';
@ -17,7 +20,7 @@ import TableRow from '@material-ui/core/TableRow';
import {makeStyles} from '@material-ui/core/styles';
import {saveConfig} from "../api/bbgo";
import {ping, saveConfig, setupRestart} from "../api/bbgo";
import Box from "@material-ui/core/Box";
import Alert from "@material-ui/lab/Alert";
@ -45,6 +48,7 @@ const useStyles = makeStyles((theme) => ({
export default function SaveConfigAndRestart({onBack, onRestarted}) {
const classes = useStyles();
const { push } = useRouter();
const [strategies, setStrategies] = React.useState([]);
const [response, setResponse] = React.useState({});
@ -56,6 +60,17 @@ export default function SaveConfigAndRestart({onBack, onRestarted}) {
saveConfig((resp) => {
setResponse(resp);
setupRestart((resp) => {
setInterval(function() {
ping(() => {
push("/");
})
}, 1000);
}).catch((err) => {
console.error(err);
setResponse(err.response.data);
})
// call restart here
}).catch((err) => {
console.error(err);