Skip to content

Commit

Permalink
Updated model for accessing only the Cloud Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Jun 9, 2020
1 parent e4d6d4b commit 251d65f
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 18 deletions.
4 changes: 2 additions & 2 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"**/.*",
"**/node_modules/**"
],
"rewrites": [
"rewrites": [
{
"source": "/api/v1/**",
"function": "wwww.webApi"
"function": "www-webApi"
}
]
}
Expand Down
13 changes: 3 additions & 10 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "cross-env-shell RUN_SERVER=true RUN_DAEMON=true firebase deploy --only functions",
"deploy-server": "cross-env-shell RUN_SERVER=true firebase deploy --only functions:www",
"deploy-server": "cross-env-shell RUN_SERVER=true \"firebase deploy --only functions\"",
"logs": "firebase functions:log",
"server": "cross-env-shell RUN_SERVER=true \"npm run build && firebase emulators:start --only functions\"",
"daemon": "cross-env-shell RUN_DAEMON=true \"npm run build && firebase emulators:start --only functions\""
Expand Down
2 changes: 1 addition & 1 deletion functions/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.use(logger('dev'));
app.use(logger('combined'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
Expand Down
6 changes: 4 additions & 2 deletions functions/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const runServer = process.env.RUN_SERVER;
const runDaemon = process.env.RUN_DAEMON;
import functions = require('firebase-functions');

const runServer = process.env.RUN_SERVER || functions.config().execution.run_server;
const runDaemon = process.env.RUN_DAEMON || functions.config().execution.run_daemon;

if (runServer === undefined && runDaemon === undefined) {
exports.www = require('./www');
Expand Down
3 changes: 1 addition & 2 deletions functions/src/bin/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const server = http.createServer(app);
*/
server.on('error', onError);
server.on('listening', onListening);
if (process.env.RUN_SERVER)
exports.webApi = functions.https.onRequest(app);
exports.webApi = functions.https.onRequest(app);

/**
* Normalize a port into a number, string or false
Expand Down
33 changes: 33 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>
65 changes: 65 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>

<!-- update the version number as needed -->
<script defer src="/__/firebase/7.14.5/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/7.14.5/firebase-auth.js"></script>
<script defer src="/__/firebase/7.14.5/firebase-database.js"></script>
<script defer src="/__/firebase/7.14.5/firebase-messaging.js"></script>
<script defer src="/__/firebase/7.14.5/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px; border-radius: 3px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>Welcome</h2>
<h1>Firebase Hosting Setup Complete</h1>
<p>You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!</p>
<a target="_blank" href="https://firebase.google.com/docs/hosting/">Open Hosting Documentation</a>
</div>
<p id="load">Firebase SDK Loading&hellip;</p>

<script>
document.addEventListener('DOMContentLoaded', function() {
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
// // The Firebase SDK is initialized and available here!
//
// firebase.auth().onAuthStateChanged(user => { });
// firebase.database().ref('/path/to/ref').on('value', snapshot => { });
// firebase.messaging().requestPermission().then(() => { });
// firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { });
//
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

try {
let app = firebase.app();
let features = ['auth', 'database', 'messaging', 'storage'].filter(feature => typeof app[feature] === 'function');
document.getElementById('load').innerHTML = `Firebase SDK loaded with ${features.join(', ')}`;
} catch (e) {
console.error(e);
document.getElementById('load').innerHTML = 'Error loading the Firebase SDK, check the console.';
}
});
</script>
</body>
</html>

0 comments on commit 251d65f

Please sign in to comment.