Deploying a Vue/Nuxt application to Firebase as a Universal App with Server-Side Rendering (SS

I am currently facing challenges with deploying my Universal Nuxt.js app on Firebase. Despite attempting various methods, I have been unable to achieve full functionality.

While SSR and hosting static assets seem to be functioning properly, middleware is only executing on the client side and not on the server when deployed on firebase using firebase functions/hosting or through firebase serve.

My project structure includes:

project
└─ /functions (firebase functions including `nuxt/` built files)
└─ /src (nuxt app, created with `create-nuxt-app` starter template)
└─ /public (contains static files and built nuxt client files)
└─ firebase.json

In src/nuxt.config.js, the build options are configured as follows:

mode: 'universal',
...
buildDir: process.env.NODE_ENV === 'development' ? '.nuxt' : '../functions/nuxt',
build: {
  publicPath: process.env.NODE_ENV === 'development' ? '/public/' : '/',
  extractCSS: true,

  ...
}

The functions/package.json file specifies the use of node v8:

"engines": {
  "node": "8"
},
...

In addition, adjustments were made in functions/index.js:

// Code snippet here

The configuration specified in firebase.json instructs Firebase to utilize the function:

"rewrites": [
  {
    "source": "**",
    "function": "nuxtapp"
  }
]

All dependencies from src/package.json were also included in functions/package.json.

After running npm run build in the src folder, the built Nuxt client files and static assets are copied into the public folder for deployment on Firebase.

Although static asset hosting and SSR appear to work, issues arise with middleware and other functionalities not being executed during server-side rendering via Firebase function.

These functionalities perform as expected in both server and client environments during local development using npm run dev.

If you have any insights on how to resolve this issue on Firebase, your input would be greatly appreciated. Thank you!

Answer №1

If you're utilizing Nuxt version 2.12 and above, there's no need for the "mode" attribute in your nuxt.config.js file. Simply utilize the target property: https://nuxtjs.org/docs/configuration-glossary/configuration-target/ (Static also functions with SSR)

The middleware directory is where you can place middlewares that should run on both the client and SSR sides for each page visited by a user. However, if you require a server middleware specifically designed to work with cloud functions, consider using Nuxt server middlewares: https://nuxtjs.org/docs/configuration-glossary/configuration-servermiddleware/

(Refer to the documentation for a more detailed comparison of middlewares versus server middlewares)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with background image resizing when touched on mobile Chrome due to background-size property set to cover

My current challenge involves setting a background image for a mobile page using a new image specifically designed for mobile devices. The image is set with the property background-size: cover, and it works perfectly on all platforms except for mobile Chro ...

Unable to fetch any attributes for the <table> element with Ajax

Something odd and complex is happening as I work on creating a hand-made calendar with the intention of open sourcing it. My goal is to achieve a look similar to Google Calendar, but surpass it in functionality while maintaining an open-source model. Every ...

Problem with detecting collisions in Three.js

Currently, I am developing a simple game where players can add objects (cubes) to the scene at the position of a raycaster (mouse) click on a large ground plane. To prevent cubes from overlapping with each other, I have implemented basic collision detectio ...

Execute a function prior to making a synchronous call

Seeking guidance on a complex issue that I have encountered. In my code, I am dealing with a synchronous AJAX call and need to execute a function before this particular call is made. The function in question is a simple one: $.blockUI(); This function ...

Steer clear of downloading images while on your smartphone

As I develop a responsive website, I encounter the challenge of optimizing image loading based on viewport size. While using CSS to hide images not needed for certain viewports can reduce display clutter, it does not prevent those images from being downloa ...

Parsing HTML to access inner content

Currently, I have integrated an onClick event to an anchor tag. When the user interacts with it, my objective is to retrieve the inner HTML without relying on the id attribute. Below is the code snippet that illustrates my approach. Any assistance in acc ...

The expiration period set in expireAfterSeconds doesn't seem to be functioning as expected in the time-to-live (ttl) configuration. Rows are

Can you please take a look at my code and provide some feedback? The issue I am facing is that the record is getting deleted without specifying the number of seconds. I have tried changing from createIndex to ensureIndex but it's still not working as ...

What is the best way to input keys into the currently selected element?

During my experimentation, I discovered that several modals and dropdowns in my tests open with their input boxes automatically focused. I found a way to verify if an element is in focus, but I'm wondering if there's a quicker method to input ke ...

Contrasting include versus block in Jade

Can you explain the distinction between blocks and include in Jade template creation? How do you determine when to use each one? ...

Converting HTML widget code to NEXTjs code for integration in an application (CoinMarketCap Price Marquee Ticker)

Having trouble integrating the CoinMarketCap Price Marquee Ticker Widget into my NEXTjs app. I'm outlining my process and hoping for some suggestions from others who may have attempted this. Template Code: To embed the widget in an HTML page, here is ...

Refreshing Data on Vuetify Range Slider

My goal is to update the value as the slider position changes. [codepen]https://codepen.io/JakeHenshall/pen/WLezNg <div id="app"> <v-app id="inspire"> <v-card flat color="transparent"> <v-subheader>Tick labels</v-subheade ...

What steps can I take to prevent Geolocation from sending the information twice?

I am currently developing a crime alert platform and my goal is to automatically extract the user's longitude and latitude when they submit a new alert. However, I am encountering an issue where the submission is being duplicated, with one instance co ...

Creating a Vuetify dialog sheet with stylish rounded edges

Is there a way to implement round corners for the dialog within the v-bottom-sheet? Note that using style="border-radius:20px;" only affects the overlay, not the dialog itself. <v-bottom-sheet style="border-radius:20px;" v-model=& ...

Insert a record at the start of a data grid - JavaScript - jQuery

What is the most effective way to use jQuery for adding a new row at the top of a table? Here is an example table structure: <table id="mytable" cellpadding="0" cellspacing="0"> <tr> <td>col1</td> ...

Achieving dynamic population of a second dropdown menu based on selection from the first dropdown menu using PHP

In my current project, I am faced with the task of populating three different menus. The first menu is generated using a MySQL query in PHP and displays TV shows like "Modern Family" or "Dexter". What I want to achieve is that once a TV show is selected fr ...

Ways to create sidebar images in a dual-column layout

I am currently working on creating images for my sidebar that have the same width but different heights. I am trying to achieve this without any spaces between the images. To get a better understanding of what I am trying to do, please refer to the follow ...

Avoiding node_modules in Webpack 2 with babel-loader

After updating to Webpack 2, I've run into an issue with the "exclude" property in my "rules". It seems I can no longer pass "exclude" into "options". What is the correct approach to handling this now? Previously: { test: /\.js$/, loader: ...

Next.js is failing to infer types from getServerSideProps to NextPage

It seems like the data type specified in getServerSideProps is not being correctly passed to the page. Here is the defined model: export type TypeUser = { _id?: Types.ObjectId; name: string; email: string; image: string; emailVerified: null; p ...

How can you identify a function call within a mocked external library using JEST?

My custom module "api" contains an axios object with defined interceptors as shown below: import axios from 'axios' import VueCookie from 'vue-cookie' const api = axios.create(...) api.interceptors.response.use(config => { ... }, e ...

The app.get() method in Node JS and Express requires three parameters, and I am seeking clarification on how these parameters work

Hey there, I'm new to this and have a question regarding my code using passport-google-oauth20. app.get('/auth/google/secrets', passport.authenticate('google',{failureRedirect: '/login'}), function(req,res){ res.redirec ...