107.13.0
another absolutely massive diff * Disabled keyboard handler for focus management, the club got better at this * Input history redone entirely, the code contains comments * Completion now takes cursor position into account * Dropped autoremoval of service messages in favour of future manual deletion * Tons of typechecking cleanup and style improvements * The code now has zero errors on the strictest TS settings I know
This commit is contained in:
23
server.js
23
server.js
@@ -1,7 +1,8 @@
|
||||
import {readFileSync} from 'node:fs'
|
||||
import {createServer} from 'node:http'
|
||||
import {argv} from 'node:process'
|
||||
|
||||
const config = {host: '127.0.0.1', port: 9696}
|
||||
const config = {host: '127.0.0.1', port: 9696, filename: argv[2] ?? 'mbchc.mjs'}
|
||||
|
||||
const h_cors = {
|
||||
'Access-Control-Max-Age': '86400',
|
||||
@@ -11,23 +12,19 @@ const h_cors = {
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
// 'Access-Control-Allow-Credentials': 'false', // omit this header to disallow
|
||||
}
|
||||
const h_all = Object.assign({
|
||||
const h_all = {
|
||||
'Content-Type': 'text/javascript',
|
||||
'Cache-Control': 'no-cache',
|
||||
}, h_cors)
|
||||
...h_cors
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {import('node:http').ServerResponse} ServerResponse
|
||||
* @type {Record<string,function(ServerResponse):void>}
|
||||
*/
|
||||
const resp = {
|
||||
GET(rx) { rx.writeHead(200, h_all); rx.write(readFileSync('./mbchc.mjs')) },
|
||||
/** @type {Record<string,((request: import('node:http').ServerResponse) => void)>} */ const resp = {
|
||||
GET(rx) { rx.writeHead(200, h_all); rx.write(readFileSync(config.filename)) },
|
||||
OPTIONS(rx) { rx.writeHead(204, h_cors) },
|
||||
}
|
||||
|
||||
const server = createServer((rq, rx) => {
|
||||
resp[rq.method] && (new URL(`http://${config.host}:${config.port}${rq.url}`)).pathname === '/' ? resp[rq.method](rx) : rx.writeHead(400)
|
||||
rx.end()
|
||||
console.log('%s %d %s %s', (new Date()).toISOString(), rx.statusCode, rq.method, rq.url)
|
||||
rq.method !== undefined && resp[rq.method] !== undefined && (new URL(`http://${config.host}:${config.port}${rq.url}`)).pathname === '/' ? resp[rq.method](rx) : rx.writeHead(400)
|
||||
rx.end(() => void console.log('%s %d %s %s', (new Date()).toISOString(), rx.statusCode, rq.method, rq.url))
|
||||
})
|
||||
server.listen(config.port, config.host, () => console.log(`Server started at http://${config.host}:${config.port}`))
|
||||
server.listen(config.port, config.host, () => void console.log(`Server started at http://${config.host}:${config.port} for ${config.filename}`))
|
||||
|
Reference in New Issue
Block a user