Skip to content

Commit

Permalink
set hostname as enviromental variable
Browse files Browse the repository at this point in the history
pass var from template
  • Loading branch information
mldangelo committed Mar 24, 2017
1 parent 180631f commit 8cd8eb9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { requireUserAPI } from './middleware';
import User from '../models/User';
const port = process.env.PORT || 7999;

const isProduction = process.env.NODE_ENV === 'production';
// const isProduction = process.env.NODE_ENV === 'production';
const hostname = process.env.HOSTNAME || `http://localhost:${port}`;


passport.use(new Strategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${isProduction ? 'https://mldangelo.com' : `http://localhost:${port}`}/login/google/return`,
callbackURL: `${hostname}/login/google/return`,
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo',
scope: ['email'],
}, (token, tokenSecret, profile, done) => {
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
NODE_ENV=production
PORT=7999
HOSTNAME=http://localhost:7999

GITHUB_OAUTH=ABCDEFG

LASTFM_KEY=12345
Expand Down
13 changes: 12 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dotenv/config';
import path from 'path';
import fs from 'fs';

import express from 'express';
import bodyParser from 'body-parser';
Expand Down Expand Up @@ -65,12 +66,22 @@ if (env === 'development') { // eslint-disable-line eqeqeq

app.get('/*', (req, res) => {
res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html')));
if (req.user) { // TODO move into html body
res.write(`<script type="text/javascript">var id="${req.user._id}";</script>`);
}
res.end();
});
} else {
app.use(express.static(`${__dirname}`));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
fs.readFile(path.join(__dirname, 'dist/index.html'), 'utf8', (err, contents) => {
res.write(contents);
if (req.user) { // TODO move into html body
res.write(`<script type="text/javascript">var id="${req.user._id}";</script>`);
}
res.end();
});
// res.sendFile(path.join(__dirname, 'dist/index.html'));
});
}

Expand Down

0 comments on commit 8cd8eb9

Please sign in to comment.