1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 03:34:35 +00:00

fix: update api endpoints

This commit is contained in:
2021-10-18 11:39:14 +00:00
parent 7396f4c952
commit 936a205e66
3 changed files with 20 additions and 9 deletions

View File

@@ -14,15 +14,15 @@ const Main = (props: any) => {
const baseUrl = window.location.origin
const [isLoading, setIsLoading] = useState(false)
const [fileContentBeforeEdit, setFileContentBeforeEdit] = useState('')
const [fileContent, setFileContent] = useState('')
const [editMode, setEditMode] = useState(false)
useEffect(() => {
console.log('from main', props.selectedFilePath)
if (props.selectedFilePath !== '') {
setIsLoading(true)
axios
.get(`${baseUrl}/SASjsDrive?filepath=${props.selectedFilePath}`)
.get(`${baseUrl}/SASjsApi/files?filepath=${props.selectedFilePath}`)
.then((res: any) => {
setIsLoading(false)
setFileContent(res.data.fileContent)
@@ -32,11 +32,12 @@ const Main = (props: any) => {
const handleEditSaveBtnClick = () => {
if (!editMode) {
setFileContentBeforeEdit(fileContent)
setEditMode(true)
} else {
setIsLoading(true)
axios
.post(`${baseUrl}/SASjsDrive`, {
.post(`${baseUrl}/SASjsApi/files`, {
filePath: props.selectedFilePath,
fileContent: fileContent
})
@@ -49,7 +50,17 @@ const Main = (props: any) => {
const handleCancelExecuteBtnClick = () => {
if (editMode) {
setFileContent(fileContentBeforeEdit)
setEditMode(false)
} else {
setIsLoading(true)
axios
.get(`${baseUrl}/SASjsExecutor/do?_program=${props.selectedFilePath}`)
.then((res) => {
setIsLoading(false)
setEditMode(false)
console.log(res)
})
}
}

View File

@@ -41,7 +41,7 @@ const SideBar = (props: any) => {
const [directoryData, setDirectoryData] = useState<TreeNode | null>(null)
useEffect(() => {
axios.get(`${baseUrl}/SASjsExecutor`).then((res: any) => {
axios.get(`${baseUrl}/SASjsApi/executor`).then((res: any) => {
if (res.data && res.data?.status === 'success') {
setDirectoryData(res.data.tree)
}

View File

@@ -13,7 +13,7 @@ import { getTmpFilesFolderPath } from '../utils'
const router = express.Router()
router.get('/', async (_, res) => {
res.status(200).send('Welcome to @sasjs/server API')
res.sendFile(path.join(__dirname, '..', '..', 'Web', 'build', 'index.html'))
})
router.post('/deploy', async (req, res) => {
@@ -44,21 +44,21 @@ router.post('/deploy', async (req, res) => {
})
})
router.get('/SASjsDrive', async (req, res) => {
router.get('/SASjsApi/files', async (req, res) => {
if (req.query.filepath) {
const fileContent = await sasjsDrive(req.query.filepath as string, 'read')
res.status(200).send({ status: 'success', fileContent: fileContent })
} else {
res.sendFile(path.join(__dirname, '..', '..', 'Web', 'build', 'index.html'))
throw 'Invalid Request: File path is not provided.'
}
})
router.post('/SASjsDrive', async (req, res) => {
router.post('/SASjsApi/files', async (req, res) => {
await sasjsDrive(req.body.filePath as string, 'update', req.body.fileContent)
res.status(200).send({ status: 'success' })
})
router.get('/SASjsExecutor', async (req, res) => {
router.get('/SASjsApi/executor', async (req, res) => {
const tree = sasjsExecutor()
res.status(200).send({ status: 'success', tree })
})