summaryrefslogtreecommitdiff
path: root/server.js
blob: c1058c79b24de57d67bc4c4193b4736e10fb13bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const http = require('http')
const fs = require('fs')

const PORT = 8080

http
    .createServer((request, response) => {
        fs.readFile(`.${request.url}`, (err, data) => {
            if (err) {
                response.writeHeader(404, {
                    'Content-Type': 'text/plain'
                })
                response.write('404 Not Found')
                response.end()
                return
            }

            if (request.url.endsWith('.html')) {
                response.writeHeader(200, {
                    'Content-Type': 'text/html'
                })
            }

            if (request.url.endsWith('.js')) {
                response.writeHeader(200, {
                    'Content-Type': 'application/javascript'
                })
            }
            if (request.url.endsWith('.wasm')) {
                response.writeHeader(200, {
                    'Content-Type': 'application/wasm'
                })
            }

            response.write(data)
            response.end()
        })
    })
    .listen(PORT)