test
This commit is contained in:
parent
bbb19375cf
commit
8a93df3e09
@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx src/index.ts"
|
"dev": "nodemon --watch src --exec tsx src/index.ts"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||||
|
13
src/app.ts
13
src/app.ts
@ -25,7 +25,8 @@ const server = http.createServer((req: http.IncomingMessage, res) => {
|
|||||||
res.end('Method not allowed');
|
res.end('Method not allowed');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const vivid = new Vivid();
|
|
||||||
|
const vivid = new Vivid({ pathname });
|
||||||
const accept = req.headers['accept'];
|
const accept = req.headers['accept'];
|
||||||
if (accept && accept.includes('text/html')) {
|
if (accept && accept.includes('text/html')) {
|
||||||
res.setHeader('Content-Type', '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())`);
|
res.end(`console.log(new Date())`);
|
||||||
return;
|
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.statusCode = 406;
|
||||||
res.end('Not Acceptable');
|
res.end('Not Acceptable');
|
||||||
});
|
});
|
||||||
|
3
src/demo/a.html
Normal file
3
src/demo/a.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div class="title" contenteditable="true">
|
||||||
|
这是一个标题
|
||||||
|
</div>
|
3
src/demo/a.js
Normal file
3
src/demo/a.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const onButtonClick = () => {
|
||||||
|
console.log('button clicked');
|
||||||
|
};
|
@ -1,6 +1,10 @@
|
|||||||
|
type VividOptions = {
|
||||||
|
pathname?: string;
|
||||||
|
};
|
||||||
export class Vivid {
|
export class Vivid {
|
||||||
pathname: string;
|
pathname: string;
|
||||||
constructor() {
|
constructor(opts?: VividOptions) {
|
||||||
|
this.pathname = opts?.pathname || '';
|
||||||
console.log('Vivid constructor');
|
console.log('Vivid constructor');
|
||||||
}
|
}
|
||||||
getContent() {
|
getContent() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user