No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    api via express

    Framework
    2
    5
    1593
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      frt last edited by frt

      how to use quasar in parallel with Express in way it used in Nuxt (https://ru.nuxtjs.org/api/nuxt-render/ or as serverMiddleware in nuxt.config.js) ?

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by s.molinari

        Firstly, Nuxt isn’t offering an API. What you linked to is how you serve up Nuxt via Express. Serving up an API is something different, which I am sure you realize. Just making sure. 😁

        Secondly, Quasar is a couple steps further than Nuxt, because it offers an environment to develop an SSR app in, then “build” and “serve” it. Note, the serving being mainly for testing purposes locally.

        So, you use

        quasar dev -m ssr //-m = --mode

        to develop your app.

        Then use

        quasar build -m ssr

        to build your app.

        Then use

        quasar serve

        to serve your app (again, only for testing purposes locally).

        More on it here: https://v1.quasar-framework.org/quasar-cli/developing-ssr/introduction

        This should also be interesting: https://v1.quasar-framework.org/quasar-cli/cli-documentation/commands-list#Custom-Node-server

        Scott

        1 Reply Last reply Reply Quote 0
        • F
          frt last edited by frt

          Yes, I very poorly and incorrectly put it.

          What I want is the proxying of api requests to a separate express server, which will process them and return the data.
          In the nuxt’s /nuxt.config,js you can specify an api request handler as a parameter:

          module.exports = {
          serverMiddleware: [
              // Will register file from project api directory to handle /api/* requires
              { path: '/api', handler: '~/api/index.js' },
            ],
          }
          

          in api/index.js:

          const express = require('express');
          const bodyParser = require('body-parser');
          
          const app = express();
          app.use(bodyParser.json());
          
          // Register API routes
          const module1 = require('./routes/module1');
          const module2 = require('./routes/module2');
          
          // Import API Routes
          app.use('/user', module1);
          app.use('/item', module2);
          
          // Export the server middleware
          module.exports = {
            path: '/api',
            handler: app,
          };
          

          Yes, in quasar, I achieved the same result by importing modules into the srs-ssr/extension.js:

          const module1 = require('../api/routes/module1');
          const module2 = require('../api/routes/module2');
          
          app.use('/api/user', module1);
          app.use('/api/item', module2);
          

          It’s works in dev mode. But after build, quasar generate dist folder and required paths to modules become invalid. In addition, this solution is only for the SSR mode and is not cross-platform, which, it seems to me, is stupid and looks like a crutch.

          I hope this time I described my problem in more detail in understanding how to solve this, as it initially seemed to me, trivial task. 😁
          Thanks for the help

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by

            If you mean cross platform as in for mobile (via Cordova) and desktop (via Electron) well, SSR mode is only for SSR type applications i.e. with a web server i.e. for a website/ SPA/ WPA. You wouldn’t have an SSR Cordova or Electron build. Right?

            Try keeping everything you need server-side within the src-ssr folder. It seems you are going up a level in your folder hierarchy and when the build is made, that folder hierarchy is lost.

            Scott

            1 Reply Last reply Reply Quote 0
            • F
              frt last edited by

              Yes, I finally realized my mistake in understanding the work of the cross-platform application and realized that the option I chose was irrational and meaningless. Many thanks for the clarification.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post