From 3ea012cf93caf8e534fda1ba6e15f0c0b9b7b7ef Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Sat, 7 Oct 2023 00:55:40 +0000 Subject: [PATCH] Configure the build and the start of the app in prod. Updating to version 0.1.1 --- .env.example | 8 +------- package.json | 6 +++++- src/frontend/components/App.tsx | 19 +++++++++++-------- src/server/config/config.go | 3 ++- src/server/main.go | 4 ++++ webpack.config.ts | 6 +++--- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.env.example b/.env.example index f90dd93..b83b7c6 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,4 @@ #Environment ENV= #Default production #App Port -PORT= #Default 80 -#PUBLIC URL -PUBLIC_URL= #Default 'auto' -#Prefix URL -PREFIX_URL= #Default '' -#ONLY EXACT PATH -ONLY_EXACT_PATH= #Default false \ No newline at end of file +PORT= #Default 80 \ No newline at end of file diff --git a/package.json b/package.json index c4f5a7a..924c999 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,14 @@ { "name": "@aleleba/create-react-go-ssr", - "version": "0.1.0", + "version": "0.1.1", "description": "Starter Kit of server side render of react", "bin": "./bin/cli.js", "main": "src/server/index", "scripts": { + "start": "cd build/server && ./react-server", "start-frontend:dev": "webpack watch --config webpack.config.ts", "start-server:dev": "cd src/server && go run main.go", + "build": "webpack --config webpack.config.ts && cd src/server && go build && mkdir ../../build && cp -r ./ ../../build/server && cp -r ../routes ../../build/routes && rm -rf ./react-server", "lint": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx", "lint:fix": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx --fix", "test": "jest", @@ -23,6 +25,8 @@ "keywords": [ "create react app", "react", + "go", + "golang", "ssr", "typescript", "redux" diff --git a/src/frontend/components/App.tsx b/src/frontend/components/App.tsx index 666a9c7..26764a6 100644 --- a/src/frontend/components/App.tsx +++ b/src/frontend/components/App.tsx @@ -1,15 +1,18 @@ import React, { useEffect } from 'react'; import PrincipalRoutes from './PrincipalRoutes'; +import { config } from '../../../config'; const App = () => { - useEffect(() => { - const ws = new WebSocket('wss://nmr4jbx8-3000.use.devtunnels.ms/ws'); - ws.onmessage = (event) => { - if (event.data === 'reload') { - window.location.reload(); - } - }; - }, []); + if(config.ENV === 'development') { + useEffect(() => { + const ws = new WebSocket('wss://nmr4jbx8-3000.use.devtunnels.ms/ws'); + ws.onmessage = (event) => { + if (event.data === 'reload') { + window.location.reload(); + } + }; + }, []); + } return ; }; diff --git a/src/server/config/config.go b/src/server/config/config.go index a33d12d..56e7218 100644 --- a/src/server/config/config.go +++ b/src/server/config/config.go @@ -8,6 +8,7 @@ import ( func LoadEnv() { err := godotenv.Load("../../.env") if err != nil { - log.Fatal("Error loading .env file") + // log.Fatal("Error loading .env file") + log.Println("Is no .env file") } } \ No newline at end of file diff --git a/src/server/main.go b/src/server/main.go index d494302..f80fb7f 100644 --- a/src/server/main.go +++ b/src/server/main.go @@ -21,6 +21,10 @@ func main() { //Getting the port from the environment port := os.Getenv("PORT") + if(port == "") { + port = "80" + } + paths := utils.GetRoutes() e := echo.New() diff --git a/webpack.config.ts b/webpack.config.ts index 88f37b1..cd7dfe2 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -18,7 +18,7 @@ const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); const BUILD_DIR = resolvePath(__dirname + '/src/server/web/dist'); const BUILD_DIR_CONVERSION = resolvePath(__dirname + '/src/server/web/conversion'); const BUILD_DIR_GET_STATE = resolvePath(__dirname + '/src/server/web/getstate'); -//const { InjectManifest } = require('workbox-webpack-plugin'); +const { InjectManifest } = require('workbox-webpack-plugin'); //const nodeExternals = require('webpack-node-externals'); const alias = resolveTsAliases(path.resolve('tsconfig.json')); @@ -131,10 +131,10 @@ const configReact = { new CopyPlugin({ patterns: copyPatterns }), - /*new InjectManifest({ + new InjectManifest({ swSrc: './service-worker.ts', swDest: 'service-worker.js', - }),*/ + }), ], optimization: { minimize: true,