Fixed code for TS compilation

This commit is contained in:
Adrian Victor 2024-11-16 14:15:32 -03:00
commit 76fad9a6e4
3 changed files with 22 additions and 14 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules
package-lock.json
certificate.crt
private.key
main.js

17
main.ts
View file

@ -1,10 +1,11 @@
const config = require('./config.json')
import fs, { stat } from 'fs';
import http, { IncomingMessage, ServerResponse } from 'http';
import https from 'https';
import url from 'url';
import path, { dirname } from 'path';
import mime from 'mime';
const config = require('./config.json');
import * as fs from 'fs';
import * as http from 'http';
import { IncomingMessage, ServerResponse } from 'http';
import * as https from 'https';
import * as url from 'url';
import * as path from 'path';
import * as mime from 'mime-types';
let server: http.Server | https.Server;
@ -109,7 +110,7 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
}
} else if (stats.isFile()) {
const extension = path.extname(finalPath)
const mimeType = mime.getType(extension) || config.defaultToMime;
const mimeType = mime.lookup(extension) || config.defaultToMime;
response.writeHead(200, {"content-type" : mimeType});
fs.readFile(finalPath, (err, data) => {
if (err) {

View file

@ -9,10 +9,16 @@
},
"devDependencies": {
"@types/node": "^22.9.0",
"mime-types": "^2.1.35",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
},
"dependencies": {
"mime": "^4.0.4"
},
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"esModuleInterop": true
}
}