mirror of
				https://github.com/aleleba/create-react-ssr.git
				synced 2025-10-31 06:00:39 -06:00 
			
		
		
		
	PR-421183: Adding Cypress and updating packages.
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
| /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||||
| //Dependencies of Server | ||||
| import express from 'express'; | ||||
| import webpack from 'webpack'; | ||||
| @@ -28,6 +29,8 @@ const { ENV, PORT, PREFIX_URL, ONLY_EXACT_PATH } = config; | ||||
|  | ||||
| const routesUrls = routes.map( route => route.path ); | ||||
|  | ||||
| const isWin = process.platform === 'win32'; | ||||
|  | ||||
| const app = express(); | ||||
|  | ||||
| // @ts-ignore:next-line | ||||
| @@ -46,20 +49,23 @@ if(ENV === 'development'){ | ||||
| 		})); | ||||
| }else{ | ||||
| 	const baseUrl = __dirname.replace(/\/server(.*)/,''); | ||||
| 	const baseUrlWin = __dirname.replace(/\\server(.*)/,''); | ||||
| 	const fullURL = `${baseUrl}` ; | ||||
| 	const fullURLWin = `${baseUrlWin}` ; | ||||
| 	app | ||||
| 		.use((req, res, next) => { | ||||
| 			if(!req.hashManifest) req.hashManifest = getHashManifest(); | ||||
| 			next(); | ||||
| 		}) | ||||
| 		.use(express.static(fullURL)) | ||||
| 		.use(express.static(isWin ? fullURLWin : fullURL)) | ||||
| 		.use(helmet()) | ||||
| 		.use(helmet.permittedCrossDomainPolicies()) | ||||
| 		.use(helmet({ | ||||
| 			contentSecurityPolicy: { | ||||
| 				directives: { | ||||
| 					...helmet.contentSecurityPolicy.getDefaultDirectives(), | ||||
| 					'script-src': ['\'self\'', '\'unsafe-inline\''],//"example.com" | ||||
| 					'script-src': ['\'self\'', '\'unsafe-inline\''], //"example.com" | ||||
| 					'connectSrc': ['\'self\'', '\'unsafe-inline\'', 'localhost:*'] | ||||
| 				}, | ||||
| 			}, | ||||
| 		})) | ||||
| @@ -72,8 +78,8 @@ const setResponse = (html, preloadedState, manifest) => { | ||||
| 	const mainBuild = manifest ? manifest['frontend.js'] : 'assets/app.js'; | ||||
| 	const vendorBuild = manifest ? manifest['vendors.js'] : 'assets/vendor.js'; | ||||
| 	const manifestJson = manifest ? `<link rel="manifest" href="${manifest['manifest.json']}">` : ''; | ||||
| 	const memoryFs = compiler.outputFileSystem | ||||
| 	const haveVendor = haveVendorsCss(manifest, memoryFs) | ||||
| 	const memoryFs = compiler.outputFileSystem; | ||||
| 	const haveVendor = haveVendorsCss(manifest, memoryFs); | ||||
|  | ||||
| 	return(` | ||||
|     <!DOCTYPE html> | ||||
|   | ||||
| @@ -1,14 +1,18 @@ | ||||
| import fs from 'fs'; | ||||
| import { config } from '../../config'; | ||||
|  | ||||
| const { ENV } = config | ||||
| const { ENV } = config; | ||||
|  | ||||
| const isWin = process.platform === 'win32'; | ||||
|  | ||||
| export const getHashManifest = () => { | ||||
| 	try { | ||||
| 		const baseUrl = __dirname.replace(/\/server(.*)/,''); | ||||
| 		const baseUrlWin = __dirname.replace(/\\server(.*)/,''); | ||||
| 		const fullURL = `${baseUrl}/assets/manifest-hash.json`; | ||||
| 		const readFileData = JSON.parse(fs.readFileSync(fullURL).toString()); | ||||
| 		return readFileData | ||||
| 		const fullURLWin = `${baseUrlWin}\\assets\\manifest-hash.json`; | ||||
| 		const readFileData = isWin ? JSON.parse(fs.readFileSync(fullURLWin).toString()) : JSON.parse(fs.readFileSync(fullURL).toString()); | ||||
| 		return readFileData; | ||||
| 	}catch(err){ | ||||
| 		console.error(err); | ||||
| 	} | ||||
| @@ -17,12 +21,13 @@ export const getHashManifest = () => { | ||||
| export const haveVendorsCss = (manifest, memoryFs) => { | ||||
| 	try { | ||||
| 		const baseUrl = __dirname.replace(/\/server(.*)/,''); | ||||
| 		const fullURL = `${baseUrl}${manifest ? `/${manifest['vendors.css']}` : '/build/assets/vendors.css'}`; | ||||
| 		const baseUrlWin = __dirname.replace(/\\server(.*)/,''); | ||||
| 		const fullURL = `${isWin ? baseUrlWin : baseUrl}${manifest ? `/${manifest['vendors.css']}` : '/build/assets/vendors.css'}`; | ||||
| 		ENV === 'production' && fs.readFileSync(fullURL).toString(); | ||||
| 		ENV === 'development' && memoryFs.readFileSync(fullURL).toString(); | ||||
| 		return true | ||||
| 		return true; | ||||
| 	}catch(err){ | ||||
| 		// console.error(err); | ||||
| 		return false | ||||
| 		return false; | ||||
| 	} | ||||
| }; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user