1
Fork 0

Add service-worker

This commit is contained in:
viktorstrate 2020-02-15 23:29:03 +01:00
parent 6f686a56ee
commit 108de3d6b8
5 changed files with 1006 additions and 577 deletions

View File

@ -43,7 +43,7 @@ func main() {
router.Use(auth.Middleware(db))
router.Use(cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:4001", "http://localhost:1234"},
AllowedOrigins: []string{"http://localhost:4001", "http://localhost:1234", "*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
AllowCredentials: true,

1544
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"license": "GPL-3.0",
"description": "UI app for Photoview",
"dependencies": {
"@babel/preset-env": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"apollo-cache-inmemory": "^1.6.3",
"apollo-client": "^2.6.4",
"apollo-link": "^1.2.13",
@ -12,11 +12,11 @@
"apollo-link-error": "^1.1.12",
"apollo-link-http": "^1.5.16",
"apollo-link-ws": "^1.0.19",
"babel-plugin-styled-components": "^1.10.6",
"copy-to-clipboard": "^3.2.0",
"babel-plugin-styled-components": "^1.10.7",
"copy-to-clipboard": "^3.2.1",
"downloadjs": "^1.4.7",
"graphql": "^14.5.0",
"graphql-tag": "^2.10.1",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.3",
"parcel-bundler": "^1.12.4",
"prettier": "^1.19.1",
"prop-types": "^15.7.2",
@ -28,7 +28,7 @@
"react-spring": "^8.0.27",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.88.0",
"styled-components": "^5.0.0",
"styled-components": "^5.0.1",
"subscriptions-transport-ws": "^0.9.16"
},
"scripts": {
@ -39,17 +39,21 @@
"now-build": "react-scripts build"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/core": "^7.8.4",
"@babel/plugin-transform-runtime": "^7.8.3",
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.18.0",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.3.0",
"husky": "^4.0.10",
"husky": "^4.2.3",
"isarray": "^2.0.5",
"lint-staged": "^10.0.0",
"lint-staged": "^10.0.7",
"parcel-plugin-sw-cache": "^0.3.1",
"react-router-prop-types": "^1.0.4"
},
"cache": {
"swDest": "service-worker.js"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"

View File

@ -19,4 +19,4 @@ const Main = () => (
ReactDOM.render(<Main />, document.getElementById('root'))
// TODO: Get Service Worker up and running
//registerServiceWorker()
registerServiceWorker()

View File

@ -20,17 +20,8 @@ const isLocalhost = Boolean(
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
const swUrl = `/service-worker.js`
if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.