We're trying to deploy our MERN stack app to Google's App Engine. Before we were using flex environment, but to enable redirecting to https every time, we switched to Standard env. After this change, we encountered a few problems, such as: sometimes our main ('/') page doesn't load, for some users the website remains unsecured and:
Uncaught SyntaxError: Unexpected token '<'
What could be the solution to fix all of these problems?
Below I'm attaching code snippets.
Our code structure looks like:
client
| - build
| - src
| - package.json
| - ...
routes/api
package.json
server.js
app.yaml
...
client/package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
Package.json:
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently "npm run server" "npm run client"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client",
"test": "jest"
},
App.Yaml:
runtime: nodejs12
automatic_scaling:
max_instances: 2
resources:
cpu: .5
memory_gb: 0.5
disk_size_gb: 10
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
- url: /
static_files: client/build/index.html
upload: client/build/index.html
secure: always
- url: /
static_dir: client/build
secure: always
In our server.js we have:
if (process.env.NODE_ENV === 'production') {
console.log('production')
app.use(express.static(path.join(__dirname, '/client/build')))
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build/index.html'))
})
}
const port = process.env.PORT || 5000
app.listen(port, () => console.log(`Server running on port ${port}`))
question from:
https://stackoverflow.com/questions/65916608/problem-with-deploying-mern-stack-app-to-gae-standard-env