diff --git a/.gitignore b/.gitignore index 7d5efcd..47696c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ #node_modules ignore -src/node_modules +client/node_modules server/node_modules #.envs -src/.env +client/.env server/.env #builds -src/build +client/build server/build \ No newline at end of file diff --git a/src/.babelrc b/client/.babelrc similarity index 100% rename from src/.babelrc rename to client/.babelrc diff --git a/src/.env.example b/client/.env.example similarity index 100% rename from src/.env.example rename to client/.env.example diff --git a/src/.eslintignore b/client/.eslintignore similarity index 100% rename from src/.eslintignore rename to client/.eslintignore diff --git a/src/.eslintrc.js b/client/.eslintrc.js similarity index 100% rename from src/.eslintrc.js rename to client/.eslintrc.js diff --git a/src/PRNameGenerator.ts b/client/PRNameGenerator.ts similarity index 100% rename from src/PRNameGenerator.ts rename to client/PRNameGenerator.ts diff --git a/src/config/index.js b/client/config/index.js similarity index 100% rename from src/config/index.js rename to client/config/index.js diff --git a/src/package-lock.json b/client/package-lock.json similarity index 100% rename from src/package-lock.json rename to client/package-lock.json diff --git a/src/package.json b/client/package.json similarity index 95% rename from src/package.json rename to client/package.json index b880c55..ec08b51 100644 --- a/src/package.json +++ b/client/package.json @@ -2,10 +2,10 @@ "name": "create-react-ssr", "version": "1.0.0", "description": "Starter Kit de server side render de react", - "main": "index.js", + "main": "src/server/index", "scripts": { - "start": "ts-node server", - "start:dev": "nodemon --exec 'ts-node' server/index -e js,json,ts,tsx,jsx", + "start": "ts-node src/server", + "start:dev": "nodemon --exec 'ts-node' src/server/index -e js,json,ts,tsx,jsx", "build": "webpack-cli --config webpack.config.js", "lint": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx", "lint:fix": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx --fix", diff --git a/src/public/manifest.json b/client/public/manifest.json similarity index 100% rename from src/public/manifest.json rename to client/public/manifest.json diff --git a/src/service-worker.js b/client/service-worker.js similarity index 100% rename from src/service-worker.js rename to client/service-worker.js diff --git a/src/serviceWorkerRegistration.ts b/client/serviceWorkerRegistration.ts similarity index 100% rename from src/serviceWorkerRegistration.ts rename to client/serviceWorkerRegistration.ts diff --git a/src/frontend/components/App.tsx b/client/src/frontend/components/App.tsx similarity index 100% rename from src/frontend/components/App.tsx rename to client/src/frontend/components/App.tsx diff --git a/src/frontend/components/InitialComponent.jsx b/client/src/frontend/components/InitialComponent.jsx similarity index 100% rename from src/frontend/components/InitialComponent.jsx rename to client/src/frontend/components/InitialComponent.jsx diff --git a/src/frontend/components/OtherComponent.jsx b/client/src/frontend/components/OtherComponent.jsx similarity index 100% rename from src/frontend/components/OtherComponent.jsx rename to client/src/frontend/components/OtherComponent.jsx diff --git a/src/frontend/components/PrincipalRoutes.jsx b/client/src/frontend/components/PrincipalRoutes.jsx similarity index 100% rename from src/frontend/components/PrincipalRoutes.jsx rename to client/src/frontend/components/PrincipalRoutes.jsx diff --git a/src/frontend/index.tsx b/client/src/frontend/index.tsx similarity index 93% rename from src/frontend/index.tsx rename to client/src/frontend/index.tsx index 58df0fc..310fa3b 100644 --- a/src/frontend/index.tsx +++ b/client/src/frontend/index.tsx @@ -6,11 +6,11 @@ import { BrowserRouter as Router } from 'react-router-dom'; import { Provider } from 'react-redux'; import { IInitialState } from './reducers/index.js'; import setStore from './setStore.js'; -import { config } from '../config'; +import { config } from '../../config'; import './styles/global.sass'; import App from './components/App'; -import serviceWorkerRegistration from '../serviceWorkerRegistration'; +import serviceWorkerRegistration from '../../serviceWorkerRegistration'; declare global { interface Window { diff --git a/src/frontend/reducers/index.ts b/client/src/frontend/reducers/index.ts similarity index 100% rename from src/frontend/reducers/index.ts rename to client/src/frontend/reducers/index.ts diff --git a/src/frontend/reducers/initialState.js b/client/src/frontend/reducers/initialState.js similarity index 100% rename from src/frontend/reducers/initialState.js rename to client/src/frontend/reducers/initialState.js diff --git a/src/frontend/reducers/testReducer.ts b/client/src/frontend/reducers/testReducer.ts similarity index 100% rename from src/frontend/reducers/testReducer.ts rename to client/src/frontend/reducers/testReducer.ts diff --git a/src/frontend/setStore.js b/client/src/frontend/setStore.js similarity index 94% rename from src/frontend/setStore.js rename to client/src/frontend/setStore.js index 1bc48d5..dfef2ed 100644 --- a/src/frontend/setStore.js +++ b/client/src/frontend/setStore.js @@ -2,7 +2,7 @@ import { createStore } from 'redux'; //, applyMiddleware // import { Provider } from 'react-redux'; import { composeWithDevTools as composeWithDevToolsWeb } from 'redux-devtools-extension'; -import { config } from '../config'; +import { config } from '../../config'; import reducer from './reducers'; const { env } = config; diff --git a/src/frontend/styles/global.sass b/client/src/frontend/styles/global.sass similarity index 100% rename from src/frontend/styles/global.sass rename to client/src/frontend/styles/global.sass diff --git a/src/routes/index.js b/client/src/routes/index.js similarity index 100% rename from src/routes/index.js rename to client/src/routes/index.js diff --git a/client/src/server/getHashManifest.js b/client/src/server/getHashManifest.js new file mode 100644 index 0000000..d7415bd --- /dev/null +++ b/client/src/server/getHashManifest.js @@ -0,0 +1,13 @@ +import fs from 'fs'; + +const getHashManifest = () => { + try { + const baseUrl = __dirname.replace(/\/client(.*)/,''); + const fullURL = `${baseUrl}/client/build/assets/manifest-hash.json` ; + return JSON.parse(fs.readFileSync(fullURL)); + }catch(err){ + console.error(err); + } +}; + +export default getHashManifest; diff --git a/src/server/index.js b/client/src/server/index.js similarity index 100% rename from src/server/index.js rename to client/src/server/index.js diff --git a/src/server/server.js b/client/src/server/server.js similarity index 93% rename from src/server/server.js rename to client/src/server/server.js index f278cf4..84b0e62 100644 --- a/src/server/server.js +++ b/client/src/server/server.js @@ -1,11 +1,11 @@ //Dependencies of Server import express from 'express'; -import { config } from '../config'; +import { config } from '../../config'; import webpack from 'webpack'; import helmet from 'helmet'; //Dependencies of HotReloading -import webpackConfig from '../webpack.config.dev'; +import webpackConfig from '../../webpack.config.dev'; import webpackDevMiddleware from 'webpack-dev-middleware'; import webpackHotMiddleware from 'webpack-hot-middleware'; @@ -44,12 +44,14 @@ if(env === 'development'){ heartbeat: 1000, })); }else{ + const baseUrl = __dirname.replace(/\/client(.*)/,''); + const fullURL = `${baseUrl}/client/build` ; app .use((req, res, next) => { if(!req.hashManifest) req.hashManifest = getHashManifest(); next(); }) - .use(express.static(`${__dirname}/../build`)) + .use(express.static(fullURL)) .use(helmet()) .use(helmet.permittedCrossDomainPolicies()) .use(helmet({ diff --git a/src/tsconfig.json b/client/tsconfig.json similarity index 100% rename from src/tsconfig.json rename to client/tsconfig.json diff --git a/src/webpack.config.dev.js b/client/webpack.config.dev.js similarity index 90% rename from src/webpack.config.dev.js rename to client/webpack.config.dev.js index f6fb38b..eb422fa 100644 --- a/src/webpack.config.dev.js +++ b/client/webpack.config.dev.js @@ -7,7 +7,7 @@ const ESLintPlugin = require('eslint-webpack-plugin'); const PUBLIC_URL = process.env.PUBLIC_URL || '/'; module.exports = { - entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&reload=true&autoConnect=true', './frontend/index.tsx'], + entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&reload=true&autoConnect=true', './src/frontend/index.tsx'], output: { path: path.resolve(__dirname, 'build'), filename: 'assets/app.js', @@ -16,8 +16,8 @@ module.exports = { resolve: { extensions: ['.js', '.jsx','.ts','.tsx', '.json'], alias: { - '@components': path.resolve(__dirname, 'frontend/components/'), - '@styles': path.resolve(__dirname, 'frontend/styles/'), + '@components': path.resolve(__dirname, 'src/frontend/components/'), + '@styles': path.resolve(__dirname, 'src/frontend/styles/'), } }, devtool: 'inline-source-map', diff --git a/src/webpack.config.js b/client/webpack.config.js similarity index 93% rename from src/webpack.config.js rename to client/webpack.config.js index 583eb98..26403e3 100644 --- a/src/webpack.config.js +++ b/client/webpack.config.js @@ -13,7 +13,7 @@ const { InjectManifest } = require('workbox-webpack-plugin'); const PUBLIC_URL = process.env.PUBLIC_URL || '/'; module.exports = { - entry: './frontend/index.tsx', + entry: './src/frontend/index.tsx', output: { path: path.resolve(__dirname, 'build'), filename: 'assets/app-[fullhash].js', @@ -22,8 +22,8 @@ module.exports = { resolve: { extensions: ['.js', '.jsx','.ts','.tsx', '.json'], alias: { - '@components': path.resolve(__dirname, 'frontend/components/'), - '@styles': path.resolve(__dirname, 'frontend/styles/'), + '@components': path.resolve(__dirname, 'src/frontend/components/'), + '@styles': path.resolve(__dirname, 'src/frontend/styles/'), } }, mode: 'production', diff --git a/src/server/getHashManifest.js b/src/server/getHashManifest.js deleted file mode 100644 index a7b6845..0000000 --- a/src/server/getHashManifest.js +++ /dev/null @@ -1,11 +0,0 @@ -import fs from 'fs'; - -const getHashManifest = () => { - try { - return JSON.parse(fs.readFileSync(`${__dirname}/../build/assets/manifest-hash.json`)); - }catch(err){ - console.error(err); - } -}; - -export default getHashManifest;