This source code is part of Maximilian Schwarzmüller's "Progressive Web Apps - Complete Guide" course on udemy.com.
You need Node.js installed on your machine. Simply download the installer from nodejs.org and go through the installation steps.
Once Node.js is installed, open your command prompt or terminal and navigate into this project folder. There, run npm install
to install all required dependencies.
Finally, run npm start
to start the development server and visit localhost:8080 to see the running application.
npx firebase-tools login
npx firebase-tools init
or try this or npm install -g firebase-tools
Which Firebase CLI features do you want to setup for this folder? Press Space to select features?
Functions
Hosting
Select a default Firebase project for this directory?
select your project pwa-gram
What language would you like to use to write Cloud Functions?
JavaScript
Do you want to use ESLint to catch probable bugs and enforce style?
No
Do you want to install dependencies with npm now?
Yes
What do you want to use as your public directory?
public
or just press enter
Configure as a single-page app (rewrite all urls to /index.html)?
No
File public/index.html already exists. Overwrite?
No
Inside functions
folder run firebase deploy
Then we must change our url in fetch requests to received Function URL (storePostData): https://us-central1-pwa-gram-9114d.cloudfunctions.net/storePostData
Go to this page
Настройки проекта > Сервисные аккаунты
and set project in index.js in functions folder
We must also to generate a new key and move him to functions folder
And then inside functions folder run firebase deploy
again
After each change in the index.js in functions folder file you need to redeploy
Install web-push
inside functions folder and add web-push start script to package.json "web-push": "web-push"
, then generate vapid keys npm run web-push generate-vapid-keys
After setting up the project you need to redeploy app, run firebase deploy
in root folder
After setting up the project you need to redeploy app, run firebase deploy
in root folder
Почему-то я не смог запустить formidable, доходит до момента Service Worker is Syncing new Posts
, пост сохраняется в idb.js(тоесть локально, т.к. не может свзяаться с базой) и не приходит уведомление(что пост отправлен/создан), идёт какая-то ошибка с кросдоменным запросом(хотя делаю через cors) и как следствие firebase не запускает функцию на free плане(т.к. firebase-функция не запустилась, то пост не сохранился в базу, а сохранился локально), так как там(на free плане) ограничены запросы к сторонним ресурсам, в чём причина не разбирался! переписал на busboy
https://developers.google.com/web/tools/workbox/guides/generate-service-worker/cli
Установили локально npm install workbox-cli -D
Note: были проблемы с настройкой конфигураций workbox wizard
на windows, решено установкой beta версии GoogleChrome/workbox#1542
- Нужно настроить конфигурацию, в версии 3.6.3 это команада
workbox wizard
, в версии 2+ , былоworkbox generate:sw
What is the root of your web app (i.e. which directory do you deploy)?
public/
Which file types would you like to precache?
выбираем все файлы(они по умолчанию выбраны все, так что просто жмём enter)
Where would you like your service worker file to be saved?
public/sevice-worker.js
меняем имя файла, так как не хотим переписывать свой существующий sw.js файл
Where would you like to save these configuration options? (workbox-config.js)
просто enter
- В результате мы получим workbox-config.js в корне проекта и дальше нужно сгенерировать sw-файл
workbox generateSW workbox-config.js
- Customizing the service worker
Вместо workbox generateSW workbox-config.js
запускаем команду workbox injectManifest workbox-config.js
, предварительно добавляем свои собственные настройки в файл sw-base.js
, а также добавляем в конфиг workbox-config.js
путь к нашим настройкам swSrc: "public/sw-base.js",
При изменении конфига или базовых настроек, нужно сгенерировать новый service-worker.js
https://developers.google.com/web/tools/workbox/modules/workbox-cli#configuration
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v2
https://developers.google.com/web/tools/workbox/reference-docs/latest/workbox.strategies
https://developers.google.com/web/tools/workbox/guides/using-plugins
Конечно же sw.js нам больше не нужен, теперь в качестве сервис-воркера мы используем service-worker.js и workbox
Про formidable и busboy
https://stackoverflow.com/questions/45098305/firebase-cloud-function-for-file-upload/45253054
https://cloud.google.com/functions/docs/writing/http#multipart_data
Upload files:
https://cloud.google.com/nodejs/docs/reference/storage/2.3.x/Bucket#upload
https://github.com/googleapis/nodejs-storage/releases/tag/v2.0.0
Repos:
https://github.com/ittus/pwa-training/tree/master/project-starting-setup
https://github.com/maniksharma98144/PWAGram
https://github.com/nfgoto/pwagram
https://github.com/rovchynnyk/pwagram
Other:
https://stackoverflow.com/questions/53366474/new-project-not-showing-on-firebase-cli
https://firebase.google.com/docs/functions/quotas
https://stackoverflow.com/questions/44414185/insufficient-tokens-for-quota-administrator-and-limit-client-project-100s-of https://console.cloud.google.com/iam-admin/quotas