28 lines
821 B
JavaScript
28 lines
821 B
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import BaseController from '../core/BaseController.js';
|
|
|
|
class IndexController extends BaseController {
|
|
constructor() {
|
|
super();
|
|
}
|
|
index() {
|
|
const {ctx} = this;
|
|
console.log("访问首页");
|
|
const indexPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../views/index.html');
|
|
fs.readFile(indexPath, (err, data) => {
|
|
if (err) {
|
|
console.log('读取首页文件错误:', err.message);
|
|
ctx.response.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
ctx.response.end('500 Internal Server Error');
|
|
} else {
|
|
ctx.response.writeHead(200, { 'Content-Type': 'text/html' });
|
|
ctx.response.end(data);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export default new IndexController();
|