Serve file from root in dev server?



  • In trying to get a service worker to work, my main server can correctly serve out my sw.js from the root of the site.

    However, when running in dev, from quasar dev command, how can I serve a file from the root of the site? I need this url to work: http://localhost:8080/sw.js

    It seems that a good place for this would be in the config/index.js file, in the dev.proxyTables section, but the webpack proxyTables section (which is deprecated? - https://github.com/chimurai/http-proxy-middleware#http-proxy-middleware-options) only allows proxy to other URLs, not to pick up a local file.

    https://github.com/oliviertassinari/serviceworker-webpack-plugin seems to be another approach. However, to use it requires a change in the webpack config which isn’t available in a Quasar Framework application.

    What is the best way to do this?

    Edit:
    I had hidden the build folder in my editor, so didn’t see it. Fixed that. Now working now on trying to use the serviceworker-webpack-plugin but running into another issue (https://github.com/oliviertassinari/serviceworker-webpack-plugin/issues/16).


  • Admin

    Service workers are currently “uncharted territory” for Quasar and new to Webpack as well. Unfortunately I do not have enough time to look over it at the moment. It’s on the roadmap though as you’ve seen the PWA Github ticket. If you make any progress, please do share it. Thanks!



  • Thanks, @rstoenescu.

    I’ve got my service worker going using the copy-webpack-plugin. I added this to my webpack.base.config.js:

      var CopyWebpackPlugin = require('copy-webpack-plugin')
    

    and in the list of plugins near the bottom of that file:

    new CopyWebpackPlugin([
      {
        from: 'root/'
      }
    ])
    

    Beside src folder, I have a new folder that I called root. All the files in that folder end up in the root of the dev and build outputs.

    0_1483399863729_upload-dae7615f-6998-4726-826b-0a10353fed03

    To use them, the index.html file has:

    0_1483399942713_upload-20bb8e05-7724-4599-8033-49c771561e05

    0_1483400095716_upload-e996c9e7-0f22-457c-953c-c8ea8e1b674e

    and to get OneSignal going, add their code to themain.js file

    0_1483400272997_upload-4616ca2a-807f-4811-ad70-984ca7b86bf2

    I’m actually using the OneSignal service worker along with my own. To do this, I edited both of the OneSignal files to add a reference to mine:

    0_1483400367159_upload-4d6be286-5eca-4214-8643-4397aa61a67d

    See https://documentation.onesignal.com/docs/web-push-sdk-setup-https for OneSignal information.


  • Admin

    @glittle Nice find!



  • @glittle Could you share some of your findings with service workers and Onesignal for web push notifications, can I contact u and ask some questions?, Thanks for the post


Log in to reply
 

Looks like your connection to Quasar Framework was lost, please wait while we try to reconnect.