-
Notifications
You must be signed in to change notification settings - Fork 53
chore: remove express dependency #5680
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
Open
jmfrancois
wants to merge
31
commits into
master
Choose a base branch
from
jmfrancois/chore/remove-express-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+336
−316
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b1ca90f
chore: remove express server
jmfrancois b90c761
chore: rewrite and fix the build and serve
jmfrancois 094c827
Merge b90c7619bf89fa620c52849ccdf7612e02cc59ad into 45c63d0274629eb84…
jmfrancois ecbbe14
chore: yarn-deduplicate
github-actions[bot] f8a3a2d
Potential fix for code scanning alert no. 2706: Uncontrolled data use…
jmfrancois 1df7d3c
Potential fix for code scanning alert no. 2708: Use of externally-con…
jmfrancois abeb80d
Potential fix for code scanning alert no. 2705: Uncontrolled data use…
jmfrancois 2387952
Merge branch 'master' into jmfrancois/chore/remove-express-server
jmfrancois ccd6e41
Fix path traversal vulnerability in serveStatic function (#5696)
Copilot 33aa623
chore: prepare release (#5666)
build-travis-ci 452befb
chore: remove prepublishOnly sript
jmfrancois c828b9f
fix(http): add missing lib-esm folder (#5685)
jmfrancois 899bcb6
fix: msw usage (#5687)
jmfrancois 6ccf883
chore(CI/changeset): do not build if there are changeset files
jmfrancois b3d49ad
chore(deps): bump changesets/action from 1.5.3 to 1.6.0 (#5681)
dependabot[bot] 1c2d126
chore(deps): bump svg64 from 1.2.0 to 2.0.0 (#5147)
dependabot[bot] 7ee15b4
chore: prepare release (#5688)
build-travis-ci d081f05
fix(jest): add WritableStream support (#5691)
jmfrancois 1817e9f
chore: prepare release (#5692)
build-travis-ci cf06a79
chore(CI): count the changeset Readme.md
jmfrancois 771ae20
fix(babel): add plugin-transform-private-methods
jmfrancois 7654edd
chore: prepare release (#5693)
build-travis-ci 66f719c
test: disable Chromatic snapshots for redundant and non-visual storie…
Copilot 963ffa5
fix: re-release package not built due to CI issue
jmfrancois ad71883
chore(deps): bump chromaui/action from 13 to 14 (#5697)
dependabot[bot] 2535a45
Merge branch 'master' into jmfrancois/chore/remove-express-server
jmfrancois 2a024dc
fix: security server path
jmfrancois 36ffbac
fix: security server path
jmfrancois b88c5b8
fix: make it works
jmfrancois ffd7c0f
Merge branch 'master' into jmfrancois/chore/remove-express-server
jmfrancois 96beda4
fix: try again
jmfrancois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* eslint-disable no-console */ | ||
| /* eslint-disable no-underscore-dangle */ | ||
| import http from 'http'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
| const distRoot = path.join(__dirname, 'dist'); | ||
|
|
||
| const options = process.argv.slice(2); | ||
| const useGzip = options.includes('--gzip'); | ||
|
|
||
| // Simple static file server | ||
| function serveStatic(req, res, filePath) { | ||
| fs.readFile(filePath, (err, data) => { | ||
| if (err) { | ||
| res.writeHead(404, { 'Content-Type': 'text/plain' }); | ||
| res.end('Not Found'); | ||
| return; | ||
| } | ||
|
|
||
| const ext = path.extname(filePath); | ||
| const contentTypes = { | ||
| '.html': 'text/html', | ||
| '.js': 'application/javascript', | ||
| '.css': 'text/css', | ||
| '.json': 'application/json', | ||
| '.png': 'image/png', | ||
| '.jpg': 'image/jpeg', | ||
| '.gif': 'image/gif', | ||
| '.svg': 'image/svg+xml', | ||
| }; | ||
|
|
||
| const contentType = contentTypes[ext] || 'application/octet-stream'; | ||
| const headers = { | ||
| 'Content-Type': contentType, | ||
| 'Content-Length': data.length, | ||
| }; | ||
|
|
||
| if (useGzip) { | ||
| headers['Content-Encoding'] = 'gzip'; | ||
| } | ||
|
|
||
| res.writeHead(200, headers); | ||
| res.end(data); | ||
| }); | ||
| } | ||
|
|
||
| function resolveSafeFilePath(requestUrl) { | ||
| let pathname; | ||
| try { | ||
| const urlObj = new URL(requestUrl, 'http://localhost'); | ||
| pathname = urlObj.pathname || '/'; | ||
| } catch { | ||
| return { statusCode: 400, message: 'Bad Request' }; | ||
| } | ||
|
|
||
| let decodedPathname; | ||
| try { | ||
| decodedPathname = decodeURIComponent(pathname); | ||
| } catch { | ||
| return { statusCode: 400, message: 'Bad Request' }; | ||
| } | ||
|
|
||
| if (decodedPathname.includes('\0')) { | ||
| return { statusCode: 400, message: 'Bad Request' }; | ||
| } | ||
|
|
||
| const normalizedPathname = path.posix.normalize(decodedPathname.replace(/\\/g, '/')); | ||
| if (!normalizedPathname.startsWith('/')) { | ||
| return { statusCode: 400, message: 'Bad Request' }; | ||
| } | ||
|
|
||
| // Resolve and normalize the path, then check if file exists and resolve symlinks | ||
| let filePath = path.resolve(distRoot, '.' + normalizedPathname); | ||
|
|
||
| try { | ||
| // Use realpathSync to resolve any symbolic links and get the canonical path | ||
| filePath = fs.realpathSync(filePath); | ||
| } catch (err) { | ||
| // File doesn't exist or can't be accessed, but we'll handle this later with fs.stat | ||
| // For now, just ensure the non-canonical path is still within bounds | ||
| } | ||
|
|
||
| if (!filePath.startsWith(distRoot + path.sep) && filePath !== distRoot) { | ||
| return { statusCode: 403, message: 'Forbidden' }; | ||
| } | ||
|
|
||
| return { filePath }; | ||
| } | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| // Serve static files from dist | ||
| const { statusCode, message, filePath: resolvedFilePath } = resolveSafeFilePath(req.url); | ||
| let filePath = resolvedFilePath; | ||
| if (!filePath) { | ||
| res.writeHead(statusCode, { 'Content-Type': 'text/plain' }); | ||
| res.end(message); | ||
| return; | ||
| } | ||
|
|
||
| // Handle directory requests (serve index.html) | ||
| fs.stat(filePath, (err, stats) => { | ||
|
||
| if (!err && stats.isDirectory()) { | ||
| filePath = path.join(filePath, 'index.html'); | ||
|
|
||
| // Re-validate the path after appending index.html | ||
| try { | ||
| const realPath = fs.realpathSync(filePath); | ||
| if (!realPath.startsWith(distRoot + path.sep) && realPath !== distRoot) { | ||
| res.writeHead(403, { 'Content-Type': 'text/plain' }); | ||
| res.end('Forbidden'); | ||
| return; | ||
| } | ||
| filePath = realPath; | ||
| } catch { | ||
| // File doesn't exist, will be handled by serveStatic with 404 | ||
| } | ||
| } | ||
|
|
||
| serveStatic(req, res, filePath); | ||
| }); | ||
| }); | ||
|
|
||
| server.listen(3000, () => { | ||
| console.log('ready http://localhost:3000'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,33 @@ | ||
| const bodyParser = require('body-parser'); | ||
| const kit = require('./kit'); | ||
| const jsonForward = require('./jsonForward'); | ||
|
|
||
| const server = devServer => { | ||
| devServer.app.use(bodyParser.json()); // for parsing application/json | ||
| jsonForward(devServer.app); | ||
| kit(devServer.app); | ||
| const server = (req, res) => { | ||
| // Parse JSON body for POST/PUT requests | ||
| let body = ''; | ||
| req.on('data', chunk => { | ||
| body += chunk.toString(); | ||
| }); | ||
| req.on('end', () => { | ||
| try { | ||
| req.body = body ? JSON.parse(body) : {}; | ||
| } catch (e) { | ||
| req.body = {}; | ||
| } | ||
| // Parse query string | ||
| const url = new URL(req.url, `http://${req.headers.host}`); | ||
| req.query = Object.fromEntries(url.searchParams); | ||
| req.url = url.pathname; | ||
|
|
||
| // Route to appropriate handler | ||
| if (req.url.startsWith('/api/mock/')) { | ||
| jsonForward(req, res); | ||
| } else if (req.url.startsWith('/api/')) { | ||
| kit(req, res); | ||
| } else { | ||
| res.writeHead(404); | ||
| res.end('Not Found'); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = server; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.