MCPcopy Create free account
hub / github.com/stackgl/shader-school / createServer

Function createServer

index.js:26–112  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

24createServer(process.cwd())
25
26function createServer(root) {
27 console.error(fs.readFileSync(
28 __dirname + '/intro.txt', 'utf8'
29 ))
30
31 live().listen(livePort, function(err) {
32 if (err) throw err
33
34 answers(root, function(err) {
35 if (err) throw err
36 console.error('Done!')
37 console.error('Booting up the workshop in your browser in just a second...')
38 console.error('')
39 setTimeout(loadedAnswers, 1000)
40 })
41 })
42
43 function loadedAnswers(err) {
44 if (err) throw err
45 var exNames = Object.keys(exercises)
46 var exLinks = exNames.map(function(k) { return exercises[k] })
47 var exSlugs = exLinks.map(function(k) { return exmap[k] })
48 var exFiles = exSlugs.map(function(link, i) {
49 var dir = path.resolve(root, link)
50
51 return fs.readdirSync(dir).map(function(name) {
52 return path.resolve(dir, name)
53 })
54 })
55
56 var exRoutes = exLinks.map(function(link, i) {
57 return require('./exercises/' + link + '/server.js')(exFiles[i])
58 })
59
60 var menu = beefy({
61 cwd: path.join(__dirname, 'menu')
62 , entries: ['index.js']
63 , quiet: false
64 , watchify: false
65 })
66
67 http.createServer(function(req, res) {
68 // Force the addition of a query string. This
69 // works around an issue in beefy until it gets fixed:
70 // https://github.com/stackgl/shader-school/issues/107
71 req.url = req.url.indexOf('?') === -1
72 ? req.url + '?'
73 : req.url
74
75 var uri = url.parse(req.url).pathname
76 var paths = uri.split('/').filter(Boolean)
77
78 if (uri === '/style.css') {
79 res.setHeader('content-type', 'text/css')
80 res.end(styles())
81 return
82 }
83

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected