migrate heroku env
This commit is contained in:
parent
8f74ca70d6
commit
b97ba8f216
|
@ -0,0 +1,15 @@
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
const result = dotenv.config();
|
||||||
|
|
||||||
|
let envs;
|
||||||
|
|
||||||
|
if (!('error' in result)) {
|
||||||
|
envs = result.parsed;
|
||||||
|
} else {
|
||||||
|
envs = {};
|
||||||
|
_.each(process.env, (value, key) => envs[key] = value);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = envs;
|
|
@ -5,6 +5,7 @@ const auth = require("../middleware/auth");
|
||||||
const User = require("../schemas/User");
|
const User = require("../schemas/User");
|
||||||
const config = require("config");
|
const config = require("config");
|
||||||
|
|
||||||
|
import { jwtSecret } from '../config/config';
|
||||||
|
|
||||||
router.post("/register", async (req, res) => {
|
router.post("/register", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
@ -60,7 +61,8 @@ router.post("/login", async (req, res) => {
|
||||||
const isMatch = await bcrypt.compare(password, user.password);
|
const isMatch = await bcrypt.compare(password, user.password);
|
||||||
if (!isMatch) return res.status(400).json({ msg: "Invalid credentials." });
|
if (!isMatch) return res.status(400).json({ msg: "Invalid credentials." });
|
||||||
|
|
||||||
const token = jwt.sign({ id: user._id },config.get('jwtSecret'));
|
//const token = jwt.sign({ id: user._id },config.get('jwtSecret'));
|
||||||
|
const token = jwt.sign({ id: user._id }, jwtSecret);
|
||||||
if(token) return res
|
if(token) return res
|
||||||
.json({
|
.json({
|
||||||
token,
|
token,
|
||||||
|
|
|
@ -2,6 +2,7 @@ const express = require("express");
|
||||||
const config = require("config");
|
const config = require("config");
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
|
import { mongoURI } from './config/config';
|
||||||
|
|
||||||
// set up express
|
// set up express
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ app.listen(PORT, () => console.log(`The server has started on port: ${PORT}`));
|
||||||
// set up mongoose
|
// set up mongoose
|
||||||
|
|
||||||
mongoose.connect(
|
mongoose.connect(
|
||||||
config.get('mongoURI'),
|
//config.get('mongoURI'),
|
||||||
|
mongoURI,
|
||||||
{
|
{
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
|
|
Loading…
Reference in New Issue