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.set('trust proxy', 1)
app.use(cors({ app.use(cors({
origin: [ origin: [
'http://localhost:5000',
'https://localhost:5000',
'http://localhost:3001', 'http://localhost:3001',
], ],
credentials: true, credentials: true,
})) }))
const PORT = 3000|| process.env.PORT; const PORT = process.env.PORT;
//DATABASE CONFIG //DATABASE CONFIG
const mongoose = require("mongoose"); const mongoose = require("mongoose");
mongoose.set('useFindAndModify', false); 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, useNewUrlParser: true,
useUnifiedTopology: true useUnifiedTopology: true
}) })
@ -35,7 +37,7 @@ mongoose.connect(process.env.MONGODB_URL || CONNECTION_URI, {
//SESSION CONFIG] //SESSION CONFIG]
var MongoDBStore = require('connect-mongodb-session')(session); var MongoDBStore = require('connect-mongodb-session')(session);
var store = new MongoDBStore({ var store = new MongoDBStore({
uri: CONNECTION_URI, uri: process.env.MONGODB_URL,
collection: 'sessions' collection: 'sessions'
}); });
app.use(session({ app.use(session({
@ -49,7 +51,10 @@ app.use(session({
})); }));
if (process.env.NODE_ENV === 'production') { 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 //ROUTES CONFIG

View File

@ -16,9 +16,9 @@
"web-vitals": "^1.1.0" "web-vitals": "^1.1.0"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "node backend/server.js",
"build": "react-scripts build", "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", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
@ -27,6 +27,9 @@
"react-app", "react-app",
"react-app/jest" "react-app/jest"
] ]
},
"engines": {
"node": "10.16.0"
}, },
"browserslist": { "browserslist": {
"production": [ "production": [
@ -40,10 +43,5 @@
"last 1 safari version" "last 1 safari version"
] ]
}, },
"buildpacks": [ "proxy": "http://localhost:5000"
{
"url": "https://github.com/mars/create-react-app-buildpack"
}
],
"proxy": "http://localhost:3000"
} }

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ const Dice = ({ rolledNumberCallback, nowMoving }) => {
const [rolledNumber, setRolledNumber] = useState(); const [rolledNumber, setRolledNumber] = useState();
const [images] = useState([one, two, three, four, five, six]); const [images] = useState([one, two, three, four, five, six]);
const handleRoll = () => { 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); const utterance = new SpeechSynthesisUtterance(response.data.number);
speechSynthesis.speak(utterance); speechSynthesis.speak(utterance);
setRolledNumber(response.data.number); setRolledNumber(response.data.number);

View File

@ -57,7 +57,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
y = event.clientY - rect.top; y = event.clientY - rect.top;
for(const pawn of pawns){ for(const pawn of pawns){
if (ctx.isPointInPath(pawn.circle, x, y)) { 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(() => { .then(() => {
setHintPawn(null); setHintPawn(null);
}); });
@ -180,7 +180,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
paintPawn(ctx, positions[hintPawn.position].x, positions[hintPawn.position].y, hintPawn.color); 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 // Rerender canvas when pawns have changed
useEffect(() => { useEffect(() => {
rerenderCanvas(); rerenderCanvas();

View File

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