From 27ae05b0a335f2ca146bc5d46d2f39a394d54234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Fri, 5 Apr 2024 11:59:20 +0200 Subject: [PATCH 1/2] fix(packages/sui-ssr): copy ssr dev 404 and 500 html --- packages/sui-ssr/bin/sui-ssr-dev.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/sui-ssr/bin/sui-ssr-dev.js b/packages/sui-ssr/bin/sui-ssr-dev.js index 5650c4da1..2b2cc6e9b 100644 --- a/packages/sui-ssr/bin/sui-ssr-dev.js +++ b/packages/sui-ssr/bin/sui-ssr-dev.js @@ -3,6 +3,7 @@ const program = require('commander') const {exec} = require('child_process') +const {copyFile} = require('fs/promises') const path = require('path') const fs = require('fs') const express = require('express') @@ -19,6 +20,8 @@ const log = require('@s-ui/bundler/shared/log.js') const serverConfigFactory = require('../compiler/server.js') const TMP_PATH = '.sui' +const SRC_PATH = path.join(process.cwd(), 'src') +const PUBLIC_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/server`) const SERVER_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/server`) const STATICS_PATH = path.join(process.cwd(), './statics') const STATICS_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/statics`) @@ -63,6 +66,13 @@ const linkStatics = () => { ) } +const copyStatics = () => { + return Promise.allSettled([ + copyFile(path.join(SRC_PATH, '404.html'), path.join(PUBLIC_OUTPUT_PATH, '404.html')), + copyFile(path.join(SRC_PATH, '500.html'), path.join(PUBLIC_OUTPUT_PATH, '500.html')) + ]) +} + const initMSW = () => { return exec(`npx msw init ${STATICS_PATH}`) } @@ -153,7 +163,13 @@ const start = async ({packagesToLink, linkAll}) => { fs.mkdirSync(TMP_PATH) } - Promise.all([linkStatics(), initMSW(), compile('client', clientCompiler), compile('server', serverCompiler)]) + Promise.all([ + linkStatics(), + initMSW(), + copyStatics(), + compile('client', clientCompiler), + compile('server', serverCompiler) + ]) .then(() => { const script = nodemon({ script: `${SERVER_OUTPUT_PATH}/index.js`, From b692c3ead33bb81198e15bd69ff01b3a6a5a4fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Fri, 5 Apr 2024 12:08:29 +0200 Subject: [PATCH 2/2] fix(packages/sui-ssr): copy files --- packages/sui-ssr/bin/sui-ssr-dev.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/sui-ssr/bin/sui-ssr-dev.js b/packages/sui-ssr/bin/sui-ssr-dev.js index 2b2cc6e9b..305a92699 100644 --- a/packages/sui-ssr/bin/sui-ssr-dev.js +++ b/packages/sui-ssr/bin/sui-ssr-dev.js @@ -3,7 +3,7 @@ const program = require('commander') const {exec} = require('child_process') -const {copyFile} = require('fs/promises') +const {cp} = require('fs/promises') const path = require('path') const fs = require('fs') const express = require('express') @@ -21,7 +21,7 @@ const serverConfigFactory = require('../compiler/server.js') const TMP_PATH = '.sui' const SRC_PATH = path.join(process.cwd(), 'src') -const PUBLIC_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/server`) +const PUBLIC_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/public`) const SERVER_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/server`) const STATICS_PATH = path.join(process.cwd(), './statics') const STATICS_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/statics`) @@ -68,8 +68,8 @@ const linkStatics = () => { const copyStatics = () => { return Promise.allSettled([ - copyFile(path.join(SRC_PATH, '404.html'), path.join(PUBLIC_OUTPUT_PATH, '404.html')), - copyFile(path.join(SRC_PATH, '500.html'), path.join(PUBLIC_OUTPUT_PATH, '500.html')) + cp(path.join(SRC_PATH, '404.html'), path.join(PUBLIC_OUTPUT_PATH, '404.html'), {recursive: true}), + cp(path.join(SRC_PATH, '500.html'), path.join(PUBLIC_OUTPUT_PATH, '500.html'), {recursive: true}) ]) }