Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a server that serves with enough CORS headers to get modules to l…
…oad properly
- Loading branch information
1 parent
9b1d992
commit 8618179
Showing
3 changed files
with
37 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Emacs droppings | ||
*~ | ||
/node_modules |
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,32 @@ | ||
#!/usr/bin/env node | ||
|
||
const http = require('http') | ||
const serveStatic = require('serve-static') | ||
|
||
const port = 8000 | ||
const origin = `http://localhost:${port}` | ||
|
||
const staticServer = serveStatic( | ||
'examples', | ||
{ | ||
setHeaders(res, path, stat) { | ||
res.setHeader('X-Content-Type-Options', 'nosniff') | ||
res.setHeader('Access-Control-Allow-Origin', origin) | ||
} | ||
}) | ||
|
||
const server = http.createServer( | ||
(req, res) => { | ||
staticServer( | ||
req, res, | ||
() => { | ||
res.writeHead( | ||
404, | ||
{ Location: `${origin}/alice-bob-carol/index.html` }) | ||
res.end() | ||
}) | ||
}) | ||
|
||
server.listen(8000) | ||
|
||
console.log(`Try ${origin}/alice-bob-carol/index.html`) |