Fixed code for TS compilation
This commit is contained in:
parent
acc92a6d9a
commit
76fad9a6e4
3 changed files with 22 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@ node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
certificate.crt
|
certificate.crt
|
||||||
private.key
|
private.key
|
||||||
|
main.js
|
||||||
17
main.ts
17
main.ts
|
|
@ -1,10 +1,11 @@
|
||||||
const config = require('./config.json')
|
const config = require('./config.json');
|
||||||
import fs, { stat } from 'fs';
|
import * as fs from 'fs';
|
||||||
import http, { IncomingMessage, ServerResponse } from 'http';
|
import * as http from 'http';
|
||||||
import https from 'https';
|
import { IncomingMessage, ServerResponse } from 'http';
|
||||||
import url from 'url';
|
import * as https from 'https';
|
||||||
import path, { dirname } from 'path';
|
import * as url from 'url';
|
||||||
import mime from 'mime';
|
import * as path from 'path';
|
||||||
|
import * as mime from 'mime-types';
|
||||||
|
|
||||||
let server: http.Server | https.Server;
|
let server: http.Server | https.Server;
|
||||||
|
|
||||||
|
|
@ -109,7 +110,7 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
|
||||||
}
|
}
|
||||||
} else if (stats.isFile()) {
|
} else if (stats.isFile()) {
|
||||||
const extension = path.extname(finalPath)
|
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});
|
response.writeHead(200, {"content-type" : mimeType});
|
||||||
fs.readFile(finalPath, (err, data) => {
|
fs.readFile(finalPath, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
||||||
16
package.json
16
package.json
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"name" : "zephyrus-webserver",
|
"name": "zephyrus-webserver",
|
||||||
"description" : "A simple webserver that supports directory listing.",
|
"description": "A simple webserver that supports directory listing.",
|
||||||
"author" : "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>",
|
"author": "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>",
|
||||||
"version" : "1.0.0",
|
"version": "1.0.0",
|
||||||
"private" : false,
|
"private": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "ts-node main.ts"
|
"start": "ts-node main.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
|
"mime-types": "^2.1.35",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mime": "^4.0.4"
|
"mime": "^4.0.4"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es6",
|
||||||
|
"module": "commonjs",
|
||||||
|
"esModuleInterop": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue