-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from labzero/develop
Merge to master
- Loading branch information
Showing
48 changed files
with
590 additions
and
821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,7 @@ DB_NAME=your_test_db_name | |
SUPERUSER_NAME=test | ||
SUPERUSER_PASSWORD=test | ||
[email protected] | ||
USE_HTTPS=false | ||
``` | ||
|
||
Then run: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* React Starter Kit (https://www.reactstarterkit.com/) | ||
* | ||
* Copyright © 2014-present Kriasoft, LLC. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE.txt file in the root directory of this source tree. | ||
*/ | ||
|
||
import type { Agent } from "https"; | ||
import { Fetch, FetchWithCache, WindowWithApp } from "./interfaces"; | ||
|
||
declare const window: WindowWithApp; | ||
|
||
type Options = { | ||
baseUrl: string; | ||
cookie?: string; | ||
agent?: Agent; | ||
}; | ||
|
||
/** | ||
* Creates a wrapper function around the HTML5 Fetch API that provides | ||
* default arguments to fetch(...) and is intended to reduce the amount | ||
* of boilerplate code in the application. | ||
* https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch | ||
*/ | ||
function createFetch( | ||
fetch: Fetch, | ||
{ agent, baseUrl, cookie }: Options | ||
): FetchWithCache { | ||
// NOTE: Tweak the default options to suite your application needs | ||
const defaults = { | ||
agent, | ||
mode: baseUrl ? "cors" : "same-origin", | ||
credentials: baseUrl ? "include" : "same-origin", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
...(cookie ? { Cookie: cookie } : null), | ||
}, | ||
}; | ||
|
||
return async (url, cacheConfig, options) => { | ||
// Instead of making an actual HTTP request to the API, use | ||
// hydrated data available during the initial page load. | ||
if (typeof window !== "undefined" && window.App.cache !== undefined) { | ||
// eslint-disable-next-line no-param-reassign | ||
cacheConfig[url] = window.App.cache[url]; | ||
delete window.App.cache[url]; | ||
} | ||
|
||
if (cacheConfig[url]) { | ||
return Promise.resolve(cacheConfig[url]); | ||
} | ||
|
||
const response = await (url.startsWith("/api") | ||
? fetch(`${baseUrl}${url}`, { | ||
...defaults, | ||
...options, | ||
headers: { | ||
...defaults.headers, | ||
...(options && options.headers), | ||
}, | ||
}) | ||
: fetch(url, options)); | ||
|
||
const json = await response.json(); | ||
// eslint-disable-next-line no-param-reassign | ||
cacheConfig[url] = json; | ||
return json; | ||
}; | ||
} | ||
|
||
export default createFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.