-
-
Notifications
You must be signed in to change notification settings - Fork 247
Fixes #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #890
Changes from all commits
b9fc42d
c764946
11a30c0
41497b0
e813862
d268aeb
f9e6adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v18.20.4 | ||
| v24.4.1 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,41 +3,47 @@ import cors from 'cors'; | |||||||||||||||||||||||||||||||||||
| import express from 'express'; | ||||||||||||||||||||||||||||||||||||
| import fs from 'node:fs'; | ||||||||||||||||||||||||||||||||||||
| import path from 'node:path'; | ||||||||||||||||||||||||||||||||||||
| import { sandboxVersion } from '../../src/livecodes/html/sandbox/index.ts'; | ||||||||||||||||||||||||||||||||||||
| import { dirname } from './utils.ts'; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export const sandbox = ({ hostname, port }: { hostname: string; port: number }) => { | ||||||||||||||||||||||||||||||||||||
| export const sandbox = async ({ hostname, port }: { hostname: string; port: number }) => { | ||||||||||||||||||||||||||||||||||||
| const app = express(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| app.use(cors()); | ||||||||||||||||||||||||||||||||||||
| app.disable('x-powered-by'); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const sandboxDir = path.resolve(dirname, 'sandbox'); | ||||||||||||||||||||||||||||||||||||
| let sandboxVersionDir = path.resolve(sandboxDir, sandboxVersion); | ||||||||||||||||||||||||||||||||||||
| fs.readdirSync(sandboxDir).forEach((v) => { | ||||||||||||||||||||||||||||||||||||
| if (fs.statSync(path.resolve(sandboxDir, v)).isDirectory()) { | ||||||||||||||||||||||||||||||||||||
| sandboxVersionDir = path.resolve(sandboxDir, v); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| const dirs = await fs.promises.readdir(sandboxDir); | ||||||||||||||||||||||||||||||||||||
| const version = | ||||||||||||||||||||||||||||||||||||
| dirs | ||||||||||||||||||||||||||||||||||||
| .filter((v) => v.startsWith('v')) | ||||||||||||||||||||||||||||||||||||
| .map((v) => Number(v.slice(1))) | ||||||||||||||||||||||||||||||||||||
| .filter((v) => !Number.isNaN(v)) | ||||||||||||||||||||||||||||||||||||
| .sort((a, b) => b - a) | ||||||||||||||||||||||||||||||||||||
| .map((v) => 'v' + v) | ||||||||||||||||||||||||||||||||||||
| .pop() || ''; | ||||||||||||||||||||||||||||||||||||
| const sandboxVersionDir = path.resolve(sandboxDir, version); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latest sandbox version detection is inverted After sorting versions in descending order, calling - const version =
- dirs
- .filter((v) => v.startsWith('v'))
- .map((v) => Number(v.slice(1)))
- .filter((v) => !Number.isNaN(v))
- .sort((a, b) => b - a)
- .map((v) => 'v' + v)
- .pop() || '';
+ const version =
+ dirs
+ .filter((v) => v.startsWith('v'))
+ .map((v) => Number(v.slice(1)))
+ .filter((v) => !Number.isNaN(v))
+ .sort((a, b) => b - a)
+ .map((v) => 'v' + v)[0] || '';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| app.use('/', (req, res) => { | ||||||||||||||||||||||||||||||||||||
| if (req.path === '/') { | ||||||||||||||||||||||||||||||||||||
| res.set('Content-Type', 'text/html'); | ||||||||||||||||||||||||||||||||||||
| res.status(200).sendFile(path.resolve(sandboxVersionDir, 'index.html')); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| const reqPath = req.path.endsWith('/') | ||||||||||||||||||||||||||||||||||||
| let reqPath = req.path.endsWith('/') | ||||||||||||||||||||||||||||||||||||
| ? req.path + 'index.html' | ||||||||||||||||||||||||||||||||||||
| : !req.path.split('/').pop()?.includes('.') | ||||||||||||||||||||||||||||||||||||
| ? req.path + '.html' | ||||||||||||||||||||||||||||||||||||
| : req.path; | ||||||||||||||||||||||||||||||||||||
| res.set('Content-Type', 'text/html'); | ||||||||||||||||||||||||||||||||||||
| const filePath = path.resolve(dirname, 'sandbox' + reqPath); | ||||||||||||||||||||||||||||||||||||
| if (fs.existsSync(filePath)) { | ||||||||||||||||||||||||||||||||||||
| res.status(200).sendFile(filePath); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| if (reqPath.startsWith('/')) { | ||||||||||||||||||||||||||||||||||||
| reqPath = reqPath.slice(1); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| res.status(404).sendFile(path.resolve(sandboxVersionDir, 'index.html')); | ||||||||||||||||||||||||||||||||||||
| const filePath = path.resolve(sandboxDir, reqPath); | ||||||||||||||||||||||||||||||||||||
| const onError = (_err: unknown) => { | ||||||||||||||||||||||||||||||||||||
| if (res.headersSent) return; | ||||||||||||||||||||||||||||||||||||
| res.status(404).sendFile(path.resolve(sandboxVersionDir, 'index.html')); | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| res.set('Content-Type', 'text/html'); | ||||||||||||||||||||||||||||||||||||
| res.status(200).sendFile(filePath, onError); | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| app.listen(port, () => { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NODE_OPTIONS build arg is never applied
Declaring
ARG NODE_OPTIONSalone doesn’t expose it to the build environment, sonpm ci/npm run buildstill run with the default heap limit. If the goal was to avoid Node OOMs during the build, this change has no effect. Please export it (or drop the arg). Example fix:ARG NODE_OPTIONS +ENV NODE_OPTIONS=${NODE_OPTIONS}🤖 Prompt for AI Agents