diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-06-27 21:03:51 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-06-27 21:28:10 +1000 |
| commit | 96bb515a603499abb016d381f0bdb5bd51ebda92 (patch) | |
| tree | 9a1f4331b942bdbe33418ff67bf3d5f8a338e147 /src | |
| parent | 761eef9a720b8fb85786ba4dc84805fdcc0d7d48 (diff) | |
Enable client directly using server URL, while avoiding CORS restrictions
Diffstat (limited to 'src')
| -rw-r--r-- | src/App.vue | 4 | ||||
| -rw-r--r-- | src/components/SearchModal.vue | 3 | ||||
| -rw-r--r-- | src/components/TileInfoModal.vue | 4 | ||||
| -rw-r--r-- | src/lib.ts | 18 | ||||
| -rw-r--r-- | src/util.ts | 20 |
5 files changed, 24 insertions, 25 deletions
diff --git a/src/App.vue b/src/App.vue index d6c1d7a..b0aa328 100644 --- a/src/App.vue +++ b/src/App.vue @@ -83,10 +83,10 @@ import SettingsIcon from './components/icon/SettingsIcon.vue'; import HelpIcon from './components/icon/HelpIcon.vue'; // Other // Note: Import paths lack a .ts or .js extension because .ts makes vue-tsc complain, and .js makes vite complain -import {TolNode, TolMap, Action, UiOptions} from './lib'; +import {TolNode, TolMap, getServerResponse, Action, UiOptions} from './lib'; import {LayoutNode, LayoutOptions, LayoutTreeChg} from './layout'; import {initLayoutTree, initLayoutMap, tryLayout} from './layout'; -import {getServerResponse, getBreakpoint, getScrollBarWidth, arraySum, randWeightedChoice, timeout} from './util'; +import {getBreakpoint, getScrollBarWidth, arraySum, randWeightedChoice, timeout} from './util'; // Type representing auto-mode actions type AutoAction = 'move across' | 'move down' | 'move up' | Action; diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue index 4657db2..39bdbdf 100644 --- a/src/components/SearchModal.vue +++ b/src/components/SearchModal.vue @@ -38,9 +38,8 @@ import {defineComponent, PropType} from 'vue'; import SearchIcon from './icon/SearchIcon.vue'; import LogInIcon from './icon/LogInIcon.vue'; import InfoIcon from './icon/InfoIcon.vue'; -import {TolNode, TolMap, UiOptions, SearchSugg, SearchSuggResponse} from '../lib'; +import {TolNode, TolMap, getServerResponse, SearchSugg, SearchSuggResponse, UiOptions} from '../lib'; import {LayoutNode, LayoutOptions} from '../layout'; -import {getServerResponse} from '../util'; export default defineComponent({ props: { diff --git a/src/components/TileInfoModal.vue b/src/components/TileInfoModal.vue index 7d402bb..4e65f9d 100644 --- a/src/components/TileInfoModal.vue +++ b/src/components/TileInfoModal.vue @@ -59,8 +59,8 @@ import {defineComponent, PropType} from 'vue'; import CloseIcon from './icon/CloseIcon.vue'; import {LayoutNode, LayoutOptions} from '../layout'; -import {TolNode, TolMap, UiOptions, DescInfo, ImgInfo, NodeInfo, InfoResponse} from '../lib'; -import {getServerResponse, capitalizeWords} from '../util'; +import {TolNode, TolMap, getServerResponse, DescInfo, ImgInfo, NodeInfo, InfoResponse, UiOptions} from '../lib'; +import {capitalizeWords} from '../util'; export default defineComponent({ props: { @@ -25,6 +25,24 @@ export class TolNode { // Maps TolNode names to TolNode objects export type TolMap = Map<string, TolNode>; +// For server requests +const SERVER_URL = 'http://localhost:8000' +export async function getServerResponse(path: string, params: string){ + // Construct URL + let url = new URL(SERVER_URL); + url.pathname = path; + url.search = params; + // Query server + let responseObj; + try { + let response = await fetch(url.toString()); + responseObj = await response.json(); + } catch (error){ + console.log(`Error with querying ${url}: ${error}`); + return null; + } + return responseObj; +} // For server search responses export type SearchSugg = { // Represents a search-string suggestion name: string, diff --git a/src/util.ts b/src/util.ts index 1ed019c..907cce5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,23 +2,6 @@ * General utility functions */ -// For server requests -export async function getServerResponse(path: string, params: string){ - // Construct URL - let url = new URL(window.location.href); - url.pathname = path; - url.search = params; - // Query server - let responseObj; - try { - let response = await fetch(url.toString()); - responseObj = await response.json(); - } catch (error){ - console.log(`Error with querying ${url}: ${error}`); - return null; - } - return responseObj; -} // For detecting screen size export type Breakpoint = 'sm' | 'md' | 'lg'; export function getBreakpoint(): Breakpoint { @@ -31,8 +14,7 @@ export function getBreakpoint(): Breakpoint { return 'lg'; } } -// Dynamically obtains scroll bar width -// From stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript +// For getting scroll-bar width // From stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript export function getScrollBarWidth(){ // Create hidden outer div let outer = document.createElement('div'); |
