Containerization Frontend project cannot auto-refresh after code changes - reactjs

I have a frontend project that was containerized by docker and docker-compose.yml, a few months ago. It was good and can automatically refresh the page localhost:8080 after I made the code changes, Below shows the main code,
docker-compose.yml
client:
build:
context: ./client
dockerfile: ./docker/local/Dockerfile
restart: on-failure
volumes:
- ./client:/app
- /app/node_modules
networks:
- myapp
nginx:
restart: always
depends_on:
- api
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
build:
context: ./docker/local/nginx
dockerfile: Dockerfile
ports:
- "8080:80"
networks:
- myapp
nginx configurations
upstream client {
server client:3000;
}
server {
location /ws {
proxy_pass http://client;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location / {
proxy_pass http://client;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
.env file
WDS_SOCKET_PORT=0
FAST_REFRESH=false
CHOKIDAR_USEPOLLING=true
app.jsx
import React from "react";
const App = () => {
return (
<div className="App">
<h1>Hello World</h1>
</div>
);
};
export default App;
package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#reduxjs/toolkit": "^1.8.2",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^14.2.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^8.0.2",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
After I make code changes, I can get into the container, and the code does change inside and volume is working. I have no idea why the front end package will not refresh as it was few months ago. I re-installed docker and switched a new pc, but no luck still.
Can anyone provide me some insights?

This is the issue of webpack, if we add WATCHPACK_POLLING=true to the .env file, the auto refresh will be working properly.

Related

Deploy React Craco app to GCP Cloud Run Error: React Refresh runtime should not be included in the production bundle

I am trying to deploy a React app with Craco to GCP Cloud Run. I am using the Cloud Code in Visual Studio Code to deploy. It say deployment is successful, but I am getting really weird error when viewing in browser, it runs locally just fine, please help.
For build, I am using the remote build option in GCP, it autmatically create a dockerfile and use nginx to build I guess? It's really confusing.
My package.json
{
"name": "material-app",
"version": "3.1.0",
"description": "Material App Pro - React Admin & Dashboard Template",
"author": "Bootlab <support#bootlab.io>",
"private": true,
"license": "https://material-ui.com/store/license/",
"scripts": {
"start": "craco start",
"build": "craco build",
"eject": "craco eject",
"lint": "eslint src --ext .js,.jsx --fix"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"Firefox ESR",
"not dead",
"not IE 11"
],
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"dependencies": {
"#auth0/auth0-spa-js": "1.18.0",
"#craco/craco": "6.3.0",
"#date-io/date-fns": "2.11.0",
"#fullcalendar/core": "5.9.0",
"#fullcalendar/daygrid": "5.9.0",
"#fullcalendar/interaction": "5.9.0",
"#fullcalendar/react": "5.9.0",
"#mui/icons-material": "5.0.0",
"#mui/lab": "5.0.0-alpha.47",
"#mui/material": "5.0.0",
"#mui/styled-engine-sc": "5.0.0",
"#mui/styles": "5.0.0",
"#mui/system": "5.0.0",
"#mui/x-data-grid": "5.0.0-beta.1",
"#reduxjs/toolkit": "1.6.1",
"amazon-cognito-identity-js": "5.1.1",
"axios": "0.21.4",
"axios-mock-adapter": "1.20.0",
"chart.js": "3.5.1",
"css-vendor": "2.0.8",
"csvtojson": "^2.0.10",
"d3": "^7.1.1",
"date-fns": "2.24.0",
"deepmerge": "4.2.2",
"faker": "5.5.3",
"firebase": "8.10.0",
"formik": "2.2.9",
"google-map-react": "2.1.10",
"history": "5.0.1",
"i18next": "20.6.1",
"jsonwebtoken": "8.5.1",
"jss": "10.8.0",
"jwt-decode": "3.1.2",
"polished": "4.1.3",
"react": "17.0.2",
"react-app-polyfill": "2.0.0",
"react-chartjs-2": "3.0.4",
"react-dom": "17.0.2",
"react-dragula": "1.1.17",
"react-feather": "2.0.9",
"react-helmet-async": "1.1.2",
"react-i18next": "11.12.0",
"react-jvectormap": "0.0.16",
"react-perfect-scrollbar": "1.5.8",
"react-quill": "2.0.0-beta.4",
"react-redux": "7.2.5",
"react-router-dom": "6.0.0-beta.4",
"react-scripts": "4.0.3",
"react-syntax-highlighter": "15.4.4",
"redux": "4.1.1",
"redux-thunk": "2.3.0",
"styled-components": "5.3.1",
"web-vitals": "2.1.0",
"yup": "0.32.9",
"craco-alias": "3.0.1"
},
"devDependencies": {
"#babel/preset-env": "7.15.6",
"redux-devtools-extension": "2.13.9"
},
"resolutions": {
"jss": "10.8.0"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
}
}
My Craco config file:
const CracoAlias = require("craco-alias");
module.exports = {
plugins: [
{
plugin: CracoAlias,
options: {
source: "options",
baseUrl: "./",
aliases: {
"#mui/styled-engine": "./node_modules/#mui/styled-engine-sc",
},
},
},
],
};
My .docker file:
# build environment
FROM node:14-alpine as react-build
WORKDIR /app
COPY . ./
RUN yarn
RUN yarn build
# server environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template
COPY --from=react-build /app/build /usr/share/nginx/html
ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
My nginx.inf
server {
listen $PORT;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
}
The error I am getting:
Error: React Refresh runtime should not be included in the production bundle.
./node_modules/react-refresh/cjs/react-refresh-runtime.production.min.js
node_modules/react-refresh/cjs/react-refresh-runtime.production.min.js:10
__webpack_require__
/workspace/webpack/bootstrap:856
What does it mean?
Okay fixed it, modify the start script to this:
node server.js
Then add a server.js file in your root directory with this content:
//server.js
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);
It works now, craco was definitely the problem.

Deploy create-react-app-typescript on Google App Engine

I am triying to deploy an application created using CRA with Typescript into the Google Cloud App Engine service, however, for some reason, the appspot link keeps loading forever until a 502 Bad Gateway appears (the error appears sometimes, normally it just keeps loading..)
I've already checked several tutorials and questions without success.
Deploy create-react-app on Google App Engine
https://medium.com/tech-tajawal/deploying-react-app-to-google-app-engine-a6ea0d5af132
The app.yaml is the following:
env: flex
runtime: nodejs
handlers:
- url: /static/js/(.*)
static_files: build/static/js/\1
upload: build/static/js/(.*)
- url: /static/css/(.*)
static_files: build/static/css/\1
upload: build/static/css/(.*)
- url: /static/media/(.*)
static_files: build/static/media/\1
upload: build/static/media/(.*)
- url: /(.*\.(json|ico))$
static_files: build/\1
upload: build/.*\.(json|ico)$
- url: /
static_files: build/index.html
upload: build/index.html
- url: /.*
static_files: build/index.html
upload: build/index.html
env_variables:
REACT_APP_DEV_API_URL: "......"
REACT_APP_MAP_API_KEY: "........"
# [END app_yaml]
Logs of the app engine (It seems it's calling the 'npm run start' command each time I open a page)
Of course, my application works fine in dev mode and also it doesn't seem to be any problem in the deployment logs.
If someone has experienced this problem before, please let me know how to solve it. Thanks in advance.
package.json:
{
"name": "testing-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/google-map-react": "^1.1.5",
"#types/jest": "^24.0.0",
"#types/lodash": "^4.14.149",
"#types/node": "^12.0.0",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"#types/react-helmet": "^5.0.15",
"#types/react-router-dom": "^5.1.3",
"#types/styled-components": "^5.0.0",
"#types/swiper": "^5.2.1",
"axios": "^0.19.2",
"google-map-react": "^1.1.6",
"lodash.differenceby": "^4.8.0",
"lodash.throttle": "^4.1.1",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-circular-progressbar": "^2.0.3",
"react-dom": "^16.12.0",
"react-id-swiper": "^3.0.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"semantic-ui-react": "^0.88.2",
"styled-components": "^5.0.1",
"swiper": "^5.3.6",
"typescript": "~3.7.2"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^2.14.0",
"#typescript-eslint/parser": "^2.14.0",
"cross-env": "^6.0.3",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-config-react-app": "^5.1.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^2.3.0",
"gh-pages": "^2.2.0",
"jest": "^24.9.0",
"lint-staged": "^9.5.0",
"pre-commit": "^1.2.2",
"prettier": "^1.19.1"
},
"lint-staged": {
"*.js": [
"npm run lint:eslint:fix",
"git add --force"
],
"*.json": [
"prettier --write",
"git add --force"
]
},
"pre-commit": "lint:staged",
"resolutions": {
"serialize-javascript": "^2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:clean": "rimraf ./build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint:staged": "lint-staged",
"lint:eslint": "eslint --ignore-path .gitignore",
"lint:eslint:fix": "eslint --ignore-path .gitignore --fix",
"prettify": "prettier --write"
},
"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"
]
}
}
The project structure is the typical CRA with containers-components (Ignore the nginx.conf and dockerfile which I was using for testing another way with Gcloud run at the time of the photo)
Edit: Added project structure and package.json
Solved (May 18, 2020)
I changed my approach and go for a custom runtime and it worked out.
Here is the configuration I used if anyone encounter this problem in the future.
Change the runtime to custom in the App.yaml
<!-- language: lang-html -->
env: flex
runtime: custom
And include a Dockerfile with a nginx.conf for the runtime management
Dockerfile:
FROM node:8-alpine as react-build
WORKDIR /app
COPY . ./
RUN npm install
RUN npm run build
# server environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template
ENV PORT 8080
ENV HOST 0.0.0.0
RUN sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf"
COPY --from=react-build /app/build /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
server {
listen $PORT;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
}
This configuration appears in one of the tutorials here: https://cloud.google.com/community/tutorials/deploy-react-nginx-cloud-run
Thank you to #Nibrass H for suggesting some possible solutions.

Docker doesn't find semantic-ui-react

I am new to docker and I want to build a react app (with typescript) inside docker and I need to use semantic-ui-react for that.
I followed the instruction from here to build by app : https://mherman.org/blog/dockerizing-a-react-app/
I added semantic ui usingnpm i -g semantic-ui-react and this is my App.tsx:
import React from 'react';
import './App.css';
import {Button} from "semantic-ui-react";
class App extends React.PureComponent {
render() {
return (<div>
This is text
<Button>
ok
</Button>
</div>)
}
}
export default App;
When I open http://localhost:3001 I get this error :
./src/App.tsx
Module not found: Can't resolve 'semantic-ui-react' in '/app/src'
I tried to build the docker image using npm then I changed to yarn thinking it will fix.
Build commands i've used so far:
docker-compose build --no-cache && docker-compose up -d --force-recreate
docker-compose build --no-cache
docker-compose up -d --force-recreate --build
my Dockerfile
# base image
FROM node:12.2.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN cat package.json
RUN yarn install
# start app
CMD ["yarn", "start"]
my docker-compose.yml:
version: '2.2'
volumes:
frontend:
services:
frontend:
container_name: container
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- '3001:3000'
environment:
- NODE_ENV=development
I'm using Ubuntu 18.04
Inside my Dockerfile I've added cat package.json to see if semantic ui is added and it is.
Step 5/7 : RUN cat package.json
---> Running in b6bbcda3221b
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/jest": "^24.0.0",
"#types/node": "^12.0.0",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.0",
"semantic-ui-react": "^0.88.2",
"typescript": "~3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"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"
]
}
}
I've executed yarn start from terminal and there is no error and the project works fine when I open it in browser.
Why doesn't docker find the semantic ui module ?
Apparently this is a duplicate of Docker-compose: node_modules not present in a volume after npm install succeeds
And the answer from FrederikNS applies here as well. I removed
- '/app/node_modules' from volumes inside docker-compose.yml and now it recognize all modules

Webpack with Proxy - The development server has disconnected

In my React app, I'm getting the following error about a minute after connection is established:
The development server has disconnected.
Refresh the page if necessary.
If I refresh, it connects again, only to disconnect after a minute again.
Webpack was installed via create-reac-app.
This is my package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-alert": "^5.5.0",
"react-dom": "^16.8.6",
"react-hot-loader": "^4.5.3",
"react-html-parser": "^2.0.2",
"react-player": "^1.13.0",
"react-router-dom": "^5.0.0",
"react-scripts": "^3.3.0",
"react-transition-group": "^4.3.0",
"spotify-web-api-js": "^1.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.11.2"
}
}
I use a nginx proxy reverse, with the following configuration:
server {
listen 80;
location / {
proxy_pass http://client:3000;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /users {
proxy_pass http://web:5000;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
If I go to http://localhost:3000/, I don't face the issue, so it must be related to proxy.
Log:
client_1 ℹ 「wds」: Project is running at http://171.13.0.12/
client_1 ℹ 「wds」: webpack output is served from /
client_1 ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
client_1 ℹ 「wds」: 404s will fallback to /index.html
Starting the development server...
This is my webpack.config.js file:
https://pastebin.com/HF78WjLL
EDIT: I have tried, based on the answer below, to add my network to package.json, like so:
"scripts": {
"start": "HOST='0.0.0.0' react-scripts start",
...,
}
But the same error persists, just like before: it connects and quickly disconnects.
How should I fix this?
Well, react-scripts 3.3.0 working with proxy was the problem, indeed.
According to the recent issue: https://github.com/facebook/create-react-app/issues/8203,
This is related to nginx's default proxy_read_timeout 60s rule. It seems that prior react-scripts versions would reload the websocket connection when it timed out after 60s.
So, adding the following lines to nginx's dev.conf, like so:
location / {
proxy_pass http://client:3000;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
# the following two timeout rules fix CRA WDS disconnects after 60s
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
solved the problem.
The webpack dev server runs on localhost by default. Localhost is only accessible from within the container. To allow it to be accessible from the host, (i.e. outside of the container), you need to make webpack serve the bundles on a publicly reachable address, 0.0.0.0.
Add this to your config:
const config = {
...,
devServer: {
contentBase: './dist',
port: process.env.PORT || 3000,
host: '0.0.0.0'
}
...,
}
module.exports = config

Publish nestjs application in GAE

I'm learning nestjs and I followed this step by step.
The application works correctly. But I want to post it as a microservice in my GAE. I'm also able to do this part well, but when I call the address in the GPC, I'm getting the error 502 - Bad Gateway.
I believe it's something in my package.json file. But I have not figured it out yet. The following is the dependencies configuration:
   "dependencies": {
   "# nestjs / common": "^ 5.0.0",
   "# nestjs / core": "^ 5.0.0",
   "# nestjs / microservices": "^ 5.0.0",
   "# nestjs / testing": "^ 5.0.0",
   "# nestjs / websockets": "^ 5.0.0",
   "reflect-metadata": "^ 0.1.12",
   "rxjs": "^ 6.0.0",
   "typescript": "^ 2.8.0",
   "ts-node": "^ 6.0.0",
   "tsconfig-paths": "^ 3.3.1"
   },
This is my start instruction:
"start": "ts-node -r tsconfig-paths/register src/main.ts",
Finally, my app.yaml:
env: flex
runtime: nodejs
service: nestapp
You could start with the AppEngine Typescript sample project:
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/typescript
It has all the typescript compilation tools setup already. The key lines you need in your package.json scripts are:
"build": "tsc -p tsconfig.build.json",
"gcp-build": "npm run build"
"gcp-build" is a reserved task name which is always executed when deploying an AppEngine NodeJS project. This will ensure your TypeScript is compiled to JavaScript on deploy. You can read more about it here:
https://cloud.google.com/appengine/docs/standard/nodejs/running-custom-build-step
Once you have TypeScript and Express running, you can replace Express with Nest! Some other things you'll need to change, the entrypoint in package.json which AppEngine uses to run the app:
"main": "dist/main.js",
And the port in your Nest app src/main.ts:
const PORT = Number(process.env.PORT) || 8080;
await app.listen(PORT);
In your app.yaml remove env: flex just use the standard environment, it's cheaper!
runtime: nodejs10
Putting it all together, your full package.json will look something like this:
{
"name": "appengine-nest",
"description": "An example TypeScript app running on Google App Engine.",
"version": "0.0.1",
"author": "kmturley",
"license": "MIT",
"engines": {
"node": ">=8.0.0"
},
"main": "dist/main.js",
"scripts": {
"prepare": "npm run build",
"pretest": "npm run build",
"build": "tsc -p tsconfig.build.json",
"deploy": "gcloud app deploy",
"lint": "tslint -p tsconfig.json -c tslint.json",
"start": "node ./dist/main.js",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",
"test": "repo-tools test app -- dist/main.js",
"gcp-build": "npm run build"
},
"dependencies": {
"#nestjs/common": "^5.6.2",
"#nestjs/core": "^5.6.2",
"express": "^4.16.3",
"nodemon": "^1.18.9",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.3.3",
"ts-node": "^8.0.2",
"tsconfig-paths": "^3.7.0",
"typescript": "^3.0.1"
},
"devDependencies": {
"#google-cloud/nodejs-repo-tools": "^3.0.0",
"#types/express": "^4.16.0",
"tslint": "^5.11.0"
}
}
I've created an example project here:
https://github.com/kmturley/appengine-nest-angular
The changes required to a
nest new <project>
are:
package.json
(main property and some scripts)
{
...
+ "main": "dist/main.js",
"scripts": {
...
- "build": "nest build",
+ "build": "tsc -p tsconfig.build.json",
+ "gcp-build": "npm run build",
...
- "start": "nest start",
+ "start": "node ./dist/main.js",
}
...
}
src/main.ts
(add port environment variable to be listened to)
async function bootstrap() {
const app = await NestFactory.create(AppModule);
- await app.listen(3000);
+ const PORT = Number(process.env.PORT) || 8080;
+ await app.listen(PORT);
}
bootstrap();
Additionally its suggested to add a deploy script on the package.json script
with the devDependency #google-cloud/nodejs-repo-tools
+ "deploy": "gcloud app deploy"
Note: The solution is #Kim T, I just added it formatted in this way because I had troubling reading and executing it fast

Resources