Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

javascript - Deploy Nuxt sitemap with Firebase

I have a sitemap created with nuxt and firebase but when I deploy the site to firebase the sitemap throws and error since I am referencing my fireInit file but my nuxt.config.file has been moved to my firebase functions folder so I can deploy it. When I try to add the fireInit file in my firebase functions folder I then get an error because I am importing outside a module. Also when I take out my dynamic routes by commenting out my async routes function the site map doesn't show my custom domain url. It shows the https://us-central1-PROJECT_NAME.cloudfunctions.net.

File Structure

functions/
- nuxt.config (prod)
- index.js

 public/
- _nuxt/ (client)

 src/
 - nuxt.config (dev)

 firebase.json

Nuxt Config

module.exports = {

     modules: ['@nuxtjs/sitemap'],

    sitemap: {
        hostname: process.env.BASE_URL,
        exclude: ['/listings/create', '/listings/edit', '/profile/**'],
        async routes() {
            const { db } = require('./plugins/fireInit');
            const snapshots = await db.collection('listings').get();
            return snapshots.docs.map((doc) => `/listings/${doc.id}`);
        },
    },
}

./plugins/fireInit

import firebase from 'firebase/app';
import 'firebase/firestore';

const firebaseConfig = {
    apiKey: 'KEY',
    authDomain: 'KEY',
    projectId: 'KEY',
    appId: 'KEY',
    measurementId: 'KEY',
};

// init firebase
!firebase.apps.length ? firebase.initializeApp(firebaseConfig) : '';

// init services
export const db = firebase.firestore();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...