-
-
Save ErraticFox/44f7a8f95620f2e41e9cda59ec7ef89c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const firebase = require('firebase'); | |
const admin = require('firebase-admin'); | |
const express = require('express'); | |
const path = require('path'); | |
const firebaseApp = firebase.initializeApp( | |
functions.config().firebase | |
); | |
const index = require('./routes/index'); | |
const app = express(); | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'pug'); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.use('/', index); | |
app.get('/auth/facebook', function(req, res) { | |
const provider = new firebase.auth.FacebookAuthProvider(); | |
firebase.auth().signInWithPopup(provider) | |
.catch(err => console.log(err)); | |
}); | |
firebase.auth().onAuthStateChanged(function(user) { | |
if (user) console.log('user:', user); | |
}); | |
// catch 404 and forward to error handler | |
app.use(function(req, res, next) { | |
var err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
// error handler | |
app.use(function(err, req, res, next) { | |
// set locals, only providing error in development | |
res.locals.message = err.message; | |
res.locals.error = req.app.get('env') === 'development' ? err : {}; | |
// render the error page | |
res.status(err.status || 500); | |
res.render('error'); | |
}); | |
exports.app = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment