Fixed code for TS compilation
This commit is contained in:
parent
acc92a6d9a
commit
76fad9a6e4
3 changed files with 22 additions and 14 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
node_modules
|
||||
package-lock.json
|
||||
certificate.crt
|
||||
private.key
|
||||
private.key
|
||||
main.js
|
||||
17
main.ts
17
main.ts
|
|
@ -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) {
|
||||
|
|
|
|||
16
package.json
16
package.json
|
|
@ -1,18 +1,24 @@
|
|||
{
|
||||
"name" : "zephyrus-webserver",
|
||||
"description" : "A simple webserver that supports directory listing.",
|
||||
"author" : "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>",
|
||||
"version" : "1.0.0",
|
||||
"private" : false,
|
||||
"name": "zephyrus-webserver",
|
||||
"description": "A simple webserver that supports directory listing.",
|
||||
"author": "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>",
|
||||
"version": "1.0.0",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"start": "ts-node main.ts"
|
||||
},
|
||||
"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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue