MBCHC/server.js
Mute 526b51e158 ASHWGA, might as well make it a module.
Included is a minimal linter infrastructure
and a server script because [epic rant removed]
2023-12-17 03:52:43 +00:00

36 lines
967 B
JavaScript

import {readFileSync} from 'node:fs'
import {createServer} from 'node:http'
function stamp_cors(rx) {
rx.setHeader('Access-Control-Max-Age', '86400')
rx.setHeader('Access-Control-Allow-Private-Network', 'true')
rx.setHeader('Access-Control-Allow-Origin', '*')
rx.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS')
rx.setHeader('Access-Control-Allow-Headers', '*')
// rx.setHeader('Access-Control-Allow-Credentials', 'false') // omit this header to disallow
}
const server = createServer((rq, rx) => {
switch (rq.method) {
case 'GET': {
rx.statusCode = 200
stamp_cors(rx)
rx.setHeader('Content-Type', 'text/javascript')
rx.setHeader('Cache-Control', 'no-cache')
const data = readFileSync('./mbchc.mjs')
rx.write(data)
break
}
case 'OPTIONS': {
rx.statusCode = 204
stamp_cors(rx)
break
}
default: {
rx.statusCode = 400
}
}
rx.end()
})
server.listen(9696, '127.0.0.1', () => console.log('Server started.'))