Skip to content

Commit

Permalink
fixes #21, #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Feb 7, 2024
1 parent 86740bf commit 4035df7
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 75 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ RUN rustup target add wasm32-unknown-unknown

ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_arm64.deb; \
wget https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_arm64.deb; \
dpkg -i tinygo_0.27.0_arm64.deb; \
curl -L -O "https://github.com/extism/js-pdk/releases/download/v0.5.0/extism-js-aarch64-linux-v0.5.0.gz"; \
curl -L -O "https://github.com/extism/js-pdk/releases/download/v1.0.0-rc6/extism-js-aarch64-linux-v1.0.0-rc6.gz"; \
else \
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb; \
wget https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_amd64.deb; \
dpkg -i tinygo_0.27.0_amd64.deb; \
curl -L -O "https://github.com/extism/js-pdk/releases/download/v0.5.0/extism-js-x86_64-linux-v0.5.0.gz"; \
curl -L -O "https://github.com/extism/js-pdk/releases/download/v1.0.0-rc6/extism-js-x86_64-linux-v1.0.0-rc6.gz"; \
fi

RUN gunzip extism-js*.gz
Expand All @@ -48,9 +48,9 @@ RUN apt-get install binaryen
RUN curl https://get.wasmer.io -sSfL | sh

RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
curl -L -o opa https://openpolicyagent.org/downloads/v0.58.0/opa_linux_ard64_static; \
curl -L -o opa https://openpolicyagent.org/downloads/v0.61.0/opa_linux_ard64_static; \
else \
curl -L -o opa https://openpolicyagent.org/downloads/v0.58.0/opa_linux_amd64_static; \
curl -L -o opa https://openpolicyagent.org/downloads/v0.61.0/opa_linux_amd64_static; \
fi
RUN chmod 755 ./opa
RUN mv opa /usr/local/bin
Expand Down
99 changes: 62 additions & 37 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,93 @@ if (AUTHENTICATION.BASIC_AUTH === ENV.AUTH_MODE &&
return;
}

function rewriteStaticPaths(baseURL) {
async function rewriteStaticPaths(baseURL) {
const indexHTMLPath = path.join(__dirname, '..', 'ui/build/index.html');
const indexHTMLContent = fs.readFileSync(indexHTMLPath).toString();
fs.writeFileSync(indexHTMLPath,
indexHTMLContent
.replace(/src=((?!src=).)*?static/g, `src=\"${baseURL}/static`)
.replace(/href=((?!src=).)*?\/static/g, `href=\"${baseURL}/static`)
.replace(/href=((?!href=).)*?\"\/favicon/g, `href=\"${baseURL}/favicon`)
.replace(/href=((?!href=).)*?\"\/fontawesome.min.css/g, `href=\"${baseURL}/fontawesome.min.css`)
.replace(/src=((?!src=).)*?\"\/fontawesome.min.js/g, `href=\"${baseURL}/fontawesome.min.js`)
.replace(/href=((?!href=).)*?\"\/solid.min.css/g, `href=\"${baseURL}/solid.min.css`)
.replace(/src=((?!src=).)*?\"\/solid.min.js/g, `href=\"${baseURL}/solid.min.js`)
.replace(/\/{2}/g, "/")
);

// media
const directory = path.join(__dirname, "..", "ui", "build", "static", "css");
const files = fs
.readdirSync(directory)
.filter(file => file.endsWith(".css"))
.map(fileName => path.join(directory, fileName));

for (const path of files) {
const content = fs.readFileSync(path).toString();
fs.writeFileSync(path, content
.replace(/url((?!url).)*?\(\/static/g, `url=(${baseURL}/static`))
}

const solidHTMLPath = path.join(__dirname, '..', 'ui/build/solid.min.css');
const solidHTMLContent = fs.readFileSync(solidHTMLPath).toString();
fs.writeFileSync(solidHTMLPath,
solidHTMLContent
.replace(/url((?!url).)*?\(\/webfonts/g, `url(${baseURL}/webfonts`))

// /api in UI folder
const jsDirectory = path.join(__dirname, "..", "ui", "build", "static", "js");
const jsFiles = fs
.readdirSync(jsDirectory)
.filter(file => file.endsWith(".js"))
.map(fileName => path.join(jsDirectory, fileName));

for (const path of jsFiles) {
const content = fs.readFileSync(path).toString();
fs.writeFileSync(path, content
.replace(/\"\/api\"/g, `"${baseURL}/api"`)
.replace(/"\/icon-512x512.png"/g, `"${baseURL}/icon-512x512.png"`)
.replace(/".\/icon-512x512.png"/g, `"${baseURL}/icon-512x512.png"`))
}

logger.info('The baseURL has been applied')
}

function createServer(appVersion) {
const app = express();

let router;

if (process.env.BASE_URL) {
const baseURL = process.env.BASE_URL;

console.log(`has baseURL ${baseURL}`)
router = express.Router();

let baseURL = process.env.BASE_URL;
if (baseURL && baseURL !== "" && baseURL !== '/') {
console.log(`loaded baseURL : ${baseURL}`)
rewriteStaticPaths(baseURL);
} else
baseURL = ""

app.use('/', (req, _res, next) => {
if (!req.path.startsWith(baseURL))
req.url = `${baseURL}${req.path}`;
next()
})
app.use(baseURL, router);
} else {
rewriteStaticPaths("");
router = express.Router();
app.use('/', router);
}

router.use(express.static(path.join(__dirname, '..', 'ui/build')));
router.use(compression());
router.use(bodyParser.raw({
app.use(compression());
app.use(bodyParser.raw({
type: 'application/octet-stream',
limit: '10mb'
}));
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
router.use(bodyParser.text());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());

router.use('/_/healthcheck', (_, res) => {
app.use(`${baseURL}/_/healthcheck`, (_, res) => {
return res.status(200).json()
});

router.use('/', Security.extractUserFromQuery);
router.use('/', publicRouter);
router.use('/api/plugins', pluginsRouter);
router.use('/api/templates', templatesRouter);
router.use('/api/wasm', wasmRouter);
router.use('/api/version', (_, res) => res.json(appVersion));
router.use('/api/development', (_, res) => res.json(process.env.NODE_ENV === "development"));
app.use(`${baseURL}/`, Security.extractUserFromQuery);
app.use(`${baseURL}/`, publicRouter);
app.use(`${baseURL}/api/plugins`, pluginsRouter);
app.use(`${baseURL}/api/templates`, templatesRouter);
app.use(`${baseURL}/api/wasm`, wasmRouter);
app.use(`${baseURL}/api/version`, (_, res) => res.json(appVersion));
app.use(`${baseURL}/api/development`, (_, res) => res.json(process.env.NODE_ENV === "development"));

router.use('/health', (_, res) => res.json({ status: true }))
app.use(`${baseURL}/health`, (_, res) => res.json({ status: true }))

router.get('/', (_, res) => res.sendFile(path.join(__dirname, '..', 'ui/build', '/index.html')));
app.get(`${baseURL ? baseURL : '/'}`, (_, res) => res.sendFile(path.join(__dirname, '..', 'ui/build', '/index.html')));
app.use(baseURL, express.static(path.join(__dirname, '..', 'ui/build'), { redirect: false }));

return http.createServer(app);
}
Expand Down
1 change: 1 addition & 0 deletions server/routers/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ router.post('/:id/build', async (req, res) => {

const data = await Datastore.getUser(req.user.email)
let plugin = (data.plugins || []).find(p => p.pluginId === pluginId);

if (plugin.type === 'github') {
plugin.type = req.query.plugin_type;
}
Expand Down
1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"@codemirror/lang-markdown": "^6.1.0",
"@codemirror/lang-rust": "^6.0.1",
"@codemirror/legacy-modes": "^6.3.1",
"@fortawesome/fontawesome-free": "^6.2.1",
"@uiw/codemirror-theme-solarized": "^4.19.5",
"@uiw/react-codemirror": "^4.19.5",
"bootstrap": "^5.2.3",
Expand Down
Loading

0 comments on commit 4035df7

Please sign in to comment.