简体   繁体   中英

Firebase function - How to include external style.css in index.js

External style.css file is not working after deploying on server

My index.js and styles.css is in same directory.

index.js

const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
 response.send(
    `<!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
    Hello ...
    </body>
    </html>
    `);
});

Cloud Functions HTTP triggers do not serve static content (such as HTML, CSS, and JS files) by default. HTTP triggers are primarily intended for you to write code that responds to HTTP requests, like API calls.

If you want to serve static content along with HTTP requests, you should look into using Firebase Hosting along with Cloud Functions. Firebase Hosting will serve your static content, and when configured properly , it will also forward some URLs to Cloud Functions that can be serviced by code you write.

Your other option is to configure an express app in Cloud Functions, and set up some routes with it so that incoming requests that go directly to Cloud Functions can be served by content that you deployed with your functions. But I think using Firebase Hosting is probably the more common and useful option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM