1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-07 06:30:06 +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 baseUrl = window.location.origin
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [fileContentBeforeEdit, setFileContentBeforeEdit] = useState('')
const [fileContent, setFileContent] = useState('') const [fileContent, setFileContent] = useState('')
const [editMode, setEditMode] = useState(false) const [editMode, setEditMode] = useState(false)
useEffect(() => { useEffect(() => {
console.log('from main', props.selectedFilePath)
if (props.selectedFilePath !== '') { if (props.selectedFilePath !== '') {
setIsLoading(true) setIsLoading(true)
axios axios
.get(`${baseUrl}/SASjsDrive?filepath=${props.selectedFilePath}`) .get(`${baseUrl}/SASjsApi/files?filepath=${props.selectedFilePath}`)
.then((res: any) => { .then((res: any) => {
setIsLoading(false) setIsLoading(false)
setFileContent(res.data.fileContent) setFileContent(res.data.fileContent)
@@ -32,11 +32,12 @@ const Main = (props: any) => {
const handleEditSaveBtnClick = () => { const handleEditSaveBtnClick = () => {
if (!editMode) { if (!editMode) {
setFileContentBeforeEdit(fileContent)
setEditMode(true) setEditMode(true)
} else { } else {
setIsLoading(true) setIsLoading(true)
axios axios
.post(`${baseUrl}/SASjsDrive`, { .post(`${baseUrl}/SASjsApi/files`, {
filePath: props.selectedFilePath, filePath: props.selectedFilePath,
fileContent: fileContent fileContent: fileContent
}) })
@@ -49,7 +50,17 @@ const Main = (props: any) => {
const handleCancelExecuteBtnClick = () => { const handleCancelExecuteBtnClick = () => {
if (editMode) { if (editMode) {
setFileContent(fileContentBeforeEdit)
setEditMode(false) 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) const [directoryData, setDirectoryData] = useState<TreeNode | null>(null)
useEffect(() => { useEffect(() => {
axios.get(`${baseUrl}/SASjsExecutor`).then((res: any) => { axios.get(`${baseUrl}/SASjsApi/executor`).then((res: any) => {
if (res.data && res.data?.status === 'success') { if (res.data && res.data?.status === 'success') {
setDirectoryData(res.data.tree) setDirectoryData(res.data.tree)
} }

View File

@@ -13,7 +13,7 @@ import { getTmpFilesFolderPath } from '../utils'
const router = express.Router() const router = express.Router()
router.get('/', async (_, res) => { 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) => { 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) { if (req.query.filepath) {
const fileContent = await sasjsDrive(req.query.filepath as string, 'read') const fileContent = await sasjsDrive(req.query.filepath as string, 'read')
res.status(200).send({ status: 'success', fileContent: fileContent }) res.status(200).send({ status: 'success', fileContent: fileContent })
} else { } 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) await sasjsDrive(req.body.filePath as string, 'update', req.body.fileContent)
res.status(200).send({ status: 'success' }) res.status(200).send({ status: 'success' })
}) })
router.get('/SASjsExecutor', async (req, res) => { router.get('/SASjsApi/executor', async (req, res) => {
const tree = sasjsExecutor() const tree = sasjsExecutor()
res.status(200).send({ status: 'success', tree }) res.status(200).send({ status: 'success', tree })
}) })