Skip to content

Commit

Permalink
security - fix dependabot alert - ecstatic (#464)
Browse files Browse the repository at this point in the history
* 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
chenteng2016 committed Jul 13, 2021
1 parent 807e383 commit bbb5155
Show file tree
Hide file tree
Showing 5 changed files with 906 additions and 13,872 deletions.
6 changes: 3 additions & 3 deletions Simulator/utils/corsproxy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable no-console */
const corsProxy = require('cors-anywhere');

// define proxy host and utilize the same pattern for exiting corsproxy
const corsProxyHost = process.env.CORSPROXY_HOST || 'localhost';

// define proxy port and utilize the same pattern for exiting corsproxy
const corsProxyPort = process.env.CORSPROXY_PORT || 1337;
const corsProxyPort = process.env.CORSPROXY_PORT || 8889;

corsProxy.createServer({
// in default the cors proxy allows any domain as origin
Expand All @@ -19,7 +20,6 @@ corsProxy.createServer({
// for instance cookie could be added to ensure no cookie is shared
removeHeaders: [],
}).listen(corsProxyPort, corsProxyHost, () => {
/* eslint-disable no-console */
// log corsproxy's host and port
console.info(`[CORS Proxy] running at: http://${corsProxyHost}:${corsProxyPort}`);
console.log(`[CORS Proxy] serving at: http://${corsProxyHost}:${corsProxyPort}`);
});
2 changes: 1 addition & 1 deletion docs/wdc_debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tableau.log("My console message goes here!");
`package.json` file. For example, you might enter the following to change the port to 8000:

```
"http-server": "node node_modules/http-server/bin/http-server -p 8000"
"http-server": "export SERVER_PORT=8000 || set SERVER_PORT=8000 && node ./index.js"
```

* To make it easier to load files into the simulator, keep the simulator and web data connector `.html` files that you are
Expand Down
31 changes: 31 additions & 0 deletions index.js
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}`);
Loading

0 comments on commit bbb5155

Please sign in to comment.