heroku deploy

This commit is contained in:
Wenszel 2021-04-30 15:14:06 +02:00
parent 79ad7c151c
commit 068cb70c0c
9 changed files with 26 additions and 22 deletions

View File

@ -12,18 +12,20 @@ app.use(express.json());
app.set('trust proxy', 1)
app.use(cors({
origin: [
'http://localhost:5000',
'https://localhost:5000',
'http://localhost:3001',
],
credentials: true,
}))
const PORT = 3000|| process.env.PORT;
const PORT = process.env.PORT;
//DATABASE CONFIG
const mongoose = require("mongoose");
mongoose.set('useFindAndModify', false);
const CONNECTION_URI = require("./credentials.js").MONGODB_URL;
//const CONNECTION_URI = require("./credentials.js").MONGODB_URL;
mongoose.connect(process.env.MONGODB_URL || CONNECTION_URI, {
mongoose.connect(process.env.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
})
@ -35,7 +37,7 @@ mongoose.connect(process.env.MONGODB_URL || CONNECTION_URI, {
//SESSION CONFIG]
var MongoDBStore = require('connect-mongodb-session')(session);
var store = new MongoDBStore({
uri: CONNECTION_URI,
uri: process.env.MONGODB_URL,
collection: 'sessions'
});
app.use(session({
@ -49,7 +51,10 @@ app.use(session({
}));
if (process.env.NODE_ENV === 'production') {
app.use(express.static('../build'))
app.use(express.static('/app/build'))
app.get('/', (req, res) => {
res.sendFile('/app/build/index.html')
});
}
//ROUTES CONFIG

View File

@ -16,9 +16,9 @@
"web-vitals": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"start": "node backend/server.js",
"build": "react-scripts build",
"heroku-postbuild": "cd backend && npm install && node server.js && cd .. && npm install && npm run build",
"heroku-postbuild": "cd backend && npm install && cd .. && npm install && npm run build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
@ -28,6 +28,9 @@
"react-app/jest"
]
},
"engines": {
"node": "10.16.0"
},
"browserslist": {
"production": [
">0.2%",
@ -40,10 +43,5 @@
"last 1 safari version"
]
},
"buildpacks": [
{
"url": "https://github.com/mars/create-react-app-buildpack"
}
],
"proxy": "http://localhost:3000"
"proxy": "http://localhost:5000"
}

1
procfile Normal file
View File

@ -0,0 +1 @@
worker: node backend/server.js

View File

@ -14,7 +14,7 @@ function App() {
const [redirect, setRedirect] = useState();
useEffect(() => {
axios.get('http://localhost:3000/player', {
axios.get('/player', {
withCredentials:true,
})
.then(response => {
@ -26,12 +26,12 @@ function App() {
const handleExit = e => {
e.preventDefault();
window.addEventListener('unload', () => {
axios.post('http://localhost:3000/player/exit', {withCredentials:true, })
axios.post('/player/exit', {withCredentials:true, })
});
}
const idCallback = () => {
axios.get('http://localhost:3000/player/', {
axios.get('/player/', {
withCredentials:true,
})
.then(response => {

View File

@ -31,7 +31,7 @@ const Gameboard = () => {
},[pawns]);
// Fetching game data
const fetchData = useCallback(() => {
axios.get('http://localhost:3000/room/',{
axios.get('/room/',{
withCredentials:true,
}).then((response)=>{
// Filling navbar with empty player nick container

View File

@ -8,7 +8,7 @@ const NameInput = ({ idCallback }) => {
}
const handleButtonClick = () => {
axios.post('http://localhost:3000/room/add',{
axios.post('/room/add',{
name: inputValue
},{
withCredentials:true,

View File

@ -11,7 +11,7 @@ const Dice = ({ rolledNumberCallback, nowMoving }) => {
const [rolledNumber, setRolledNumber] = useState();
const [images] = useState([one, two, three, four, five, six]);
const handleRoll = () => {
axios.get('http://localhost:3000/game/roll', {withCredentials: true}).then(response => {
axios.get('/game/roll', {withCredentials: true}).then(response => {
const utterance = new SpeechSynthesisUtterance(response.data.number);
speechSynthesis.speak(utterance);
setRolledNumber(response.data.number);

View File

@ -57,7 +57,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
y = event.clientY - rect.top;
for(const pawn of pawns){
if (ctx.isPointInPath(pawn.circle, x, y)) {
axios.post('http://localhost:3000/game/move', {pawnId: pawn._id}, {withCredentials: true, mode: 'cors'})
axios.post('/game/move', {pawnId: pawn._id}, {withCredentials: true, mode: 'cors'})
.then(() => {
setHintPawn(null);
});
@ -180,7 +180,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
paintPawn(ctx, positions[hintPawn.position].x, positions[hintPawn.position].y, hintPawn.color);
}
}
},[blinking, checkIfPawnCanMove, context.color, hintPawn, nowMoving, pawns, rolledNumber]);
},[ checkIfPawnCanMove, context.color, hintPawn, nowMoving, pawns, rolledNumber]);
// Rerender canvas when pawns have changed
useEffect(() => {
rerenderCanvas();

View File

@ -7,7 +7,7 @@ const ReadyButton = () => {
const [checked, setChecked] = useState(false)
const handleCheckboxChange = () => {
axios.post('http://localhost:3000/player/ready',{},{withCredentials: true});
axios.post('/player/ready',{},{withCredentials: true});
setChecked(!checked);
}