-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
security - fix dependabot alert - ecstatic (#464)
* trim logs * add static server for recursive hosting * update start scripting * index.js is the server entrypoint * update packages * trim des * update related docs * trim updates * use stable * trim updates * enable controlling cache setting and trim updates * ensure printing the serving without spaces * support cache settings * ensure logging info
- Loading branch information
1 parent
807e383
commit bbb5155
Showing
5 changed files
with
906 additions
and
13,872 deletions.
There are no files selected for viewing
This file contains 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 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 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,31 @@ | ||
/* eslint-disable no-console */ | ||
const http = require('http'); | ||
const finalhandler = require('finalhandler'); | ||
const serveStatic = require('serve-static'); | ||
|
||
// utilize the same pattern for exiting port and cache settings | ||
const serverPortNumber = process.env.SERVER_PORT || 8888; | ||
const args = process.argv.slice(2); | ||
const disableCache = Array.isArray(args) && args.includes('--no-cache'); | ||
|
||
// disable cache | ||
const setCustomCacheControl = (res, path) => { | ||
console.log(`[HTTP Server] serving resource: ${path}`); | ||
|
||
if (disableCache) { | ||
res.setHeader('Cache-Control', 'public, max-age=0'); | ||
} | ||
}; | ||
|
||
// serve root folder supporting relative path for accessing resources and cache settings | ||
const serve = serveStatic('./', { | ||
setHeaders: setCustomCacheControl, | ||
}); | ||
|
||
const httpServer = http.createServer((req, res) => { | ||
serve(req, res, finalhandler(req, res)); | ||
}); | ||
httpServer.listen(serverPortNumber); | ||
|
||
console.log(`[HTTP Server] serving at: http://localhost:${serverPortNumber.toString().trim()}/Simulator/index.html`); | ||
console.log(`[HTTP Server] disable serving resources with cache: ${disableCache}`); |
Oops, something went wrong.