public async aapi()

in web/index.ts [227:288]


    public async aapi(resource: string, verb: axios.Method, data?: any) {

        // Conver the data to a string
        let dataString: string;
        if (data) {
            dataString = JSON.stringify(data);
        }
        const apiUrl = this.apiUrl + '/' + resource;

        console.info("aapi apiUrl", apiUrl);

        // Get the JWT token
        let jwt = Cookies.get('jwt.id');

        if (!jwt) {
            if (this.localJwt) {
                console.log('Using local testing jwt');
                jwt = this.localJwt;
            } else {
                console.log('No jwt, trying aapi, logging out');
                this.logout();
                return;
            }
        }

        // Inline function to make the API call
        const callApi = async () => {

            const resp = await axios.default({
                url: apiUrl,
                method: verb,
                data: dataString,
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + jwt
                }
            });

            console.info({ resp });

            if (resp.status === 401) {
                // Not logged in
                this.logout();
                return;
            }

            if (resp.status === 403) {
                // Not authorized
                return;
            }

            return resp.data;
        };

        const loggedIn = await this.checkExpiration();
        jwt = Cookies.get('jwt.id');

        // If false, we should get redirected to the login page
        if (loggedIn) {
            return await callApi();
        }
    }