SSR Server Scripts: I don't get it right



  • Hi guys,

    i hope someone of you can help me.
    Currently I struggle with the scripts inside the /src-ssr folder and the whole server side rendering.

    I’m not an expert in JS but I know the basics.

    My problem is that I cannot get my code inside the extension.js to work properly. Multiple problems appear:

    1. I already tried to pass the express object via a parameter inside the extendApp() function. Like this:
    // /src-ssr/index.js
    extension.extendApp({app, express});
    
    // /src-ssr/extension.js
    module.exports.extendApp = function ({app, express}) {
    

    My Intention behind this is to use the Router from the express object to learn more about express and the possibility to return json data needed inside my vue app (this RESTful api thing)

    1. Even a simple console.log() doesn’t get executed on a rebuild. I need to rerun the quasar dev -m ssr command to get some output.

    I think these issues are more or less something I misunderstood.

    One last question:

    • Is it possible to change the setup of quasar to actually use the /src-ssr/index.js in dev mode?

    Let me know if you need further code examples.
    Thanks in advance

    EDIT:
    Ok I figured out my 1. problem. Nevertheless are there new problems like a type error

    TypeError: app.Router is not a function

    I get this only when I stop the dev server. And this is the corresponding code:
    let router = app.Router();
    Even the express docs say that the function is there, also in the installed node_modules folder is the function.

     var proto = module.exports = function(options) {
      var opts = options || {};
    
      function router(req, res, next) {
        router.handle(req, res, next);
      }
    
      // mixin Router class functions
      setPrototypeOf(router, proto)
    
      router.params = {};
      router._params = [];
      router.caseSensitive = opts.caseSensitive;
      router.mergeParams = opts.mergeParams;
      router.strict = opts.strict;
      router.stack = [];
    
      return router;
    };