Test sea assets

This commit is contained in:
Cris Stringfellow 2024-07-31 19:56:27 +08:00
parent 778cd553c0
commit 3818428a8b
No known key found for this signature in database
2 changed files with 24 additions and 6 deletions

View File

@ -86,7 +86,9 @@ async function start({server_port}) {
function addHandlers() {
app.use(express.urlencoded({extended:true, limit: '50mb'}));
app.use(express.static(SITE_PATH));
if ( !sea.isSea() ) {
app.use(express.static(SITE_PATH));
}
if ( args.library_path() ) {
app.use("/library", express.static(args.library_path()))
@ -251,6 +253,19 @@ function addHandlers() {
return;
}
});
if ( sea.isSea() ) {
app.get('*', async (req, res) => {
const path = req.path;
const asset = sea.getAsset(path.slice(1)) || sea.getAsset(path.slice(1) +'.html');
if ( asset ) {
res.type(path.split('.').pop());
res.send(asset);
} else {
res.status(404).send('Not found');
}
});
}
}
async function stop() {

13
test.sh
View File

@ -1,9 +1,9 @@
#!/bin/bash
# Variables
EXE_NAME=$1
JS_SOURCE_FILE=$2
OUTPUT_FOLDER=$3
EXE_NAME="$1"
JS_SOURCE_FILE="$2"
OUTPUT_FOLDER="$3"
# Ensure nvm is installed
if ! command -v nvm &> /dev/null
@ -24,8 +24,11 @@ cat <<EOF > sea-config.json
"main": "${JS_SOURCE_FILE}",
"output": "sea-prep.blob",
"assets": {
"public": "public/**/*",
"vendor": "build/vendor/**/*"
"index.html": "public/index.html",
"top.html": "public/top.html",
"style.css": "public/style.css",
"injection.js": "public/injection.js",
"redirector.html": "public/redirector.html"
}
}
EOF