This commit is contained in:
abearxiong 2024-12-11 23:59:40 +08:00
parent bbb19375cf
commit 8a93df3e09
5 changed files with 24 additions and 3 deletions

View File

@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsx src/index.ts"
"dev": "nodemon --watch src --exec tsx src/index.ts"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me>",

View File

@ -25,7 +25,8 @@ const server = http.createServer((req: http.IncomingMessage, res) => {
res.end('Method not allowed');
return;
}
const vivid = new Vivid();
const vivid = new Vivid({ pathname });
const accept = req.headers['accept'];
if (accept && accept.includes('text/html')) {
res.setHeader('Content-Type', 'text/html');
@ -37,6 +38,16 @@ const server = http.createServer((req: http.IncomingMessage, res) => {
res.end(`console.log(new Date())`);
return;
}
if (accept && accept.includes('text/plain')) {
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
return;
}
if (accept && accept.includes('stylesheet')) {
res.setHeader('Content-Type', 'text/css');
res.end('body { background-color: red; }');
return;
}
res.statusCode = 406;
res.end('Not Acceptable');
});

3
src/demo/a.html Normal file
View File

@ -0,0 +1,3 @@
<div class="title" contenteditable="true">
这是一个标题
</div>

3
src/demo/a.js Normal file
View File

@ -0,0 +1,3 @@
const onButtonClick = () => {
console.log('button clicked');
};

View File

@ -1,6 +1,10 @@
type VividOptions = {
pathname?: string;
};
export class Vivid {
pathname: string;
constructor() {
constructor(opts?: VividOptions) {
this.pathname = opts?.pathname || '';
console.log('Vivid constructor');
}
getContent() {