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/lib.ts | |
| parent | 761eef9a720b8fb85786ba4dc84805fdcc0d7d48 (diff) | |
Enable client directly using server URL, while avoiding CORS restrictions
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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, |
