Converted server to ts w/ its own tsconfig

This commit is contained in:
2022-08-13 12:14:22 +02:00
parent 577a64a32f
commit 335155eb8f
3 changed files with 55 additions and 18 deletions

View File

@@ -1,18 +0,0 @@
const express = require("express");
const path = require("path");
const history = require("connect-history-api-fallback");
const publicPath = path.join(__dirname, "public");
app = express();
app.use("/", express.static(publicPath));
app.use(history({ index: "/" }));
app.get("/", function (req, res) {
res.sendFile(`${publicPath}/index.html`);
});
const port = process.env.PORT || 5001;
console.log("Server runnning at port:", port);
app.listen(port);

25
server.ts Normal file
View File

@@ -0,0 +1,25 @@
import express, { Express, Request, Response } from "express";
import path from "path";
const history = require("connect-history-api-fallback");
const publicPath = path.join(__dirname, "..", "public");
const app: Express = express();
app.get("/_healthz", (_, res) => {
res.status(200).send("ok");
});
app.use("/", express.static(publicPath));
app.use(history({ index: "/" }));
app.get("/", (req: Request, res: Response) => {
console.log("trying to get:", req.path);
res.sendFile(`${publicPath}/index.html`);
});
const port = process.env.PORT || 5001;
console.log("Server runnning at port:", port);
app.listen(port);

30
tsconfig.server.json Normal file
View File

@@ -0,0 +1,30 @@
{
"compilerOptions": {
"target": "esnext",
"outDir": "./lib",
"lib": ["es2017"],
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
"alwaysStrict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"noEmit": false,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"declaration": true,
"sourceMap": false,
"preserveConstEnums": true,
"skipLibCheck": true,
"removeComments": false,
"strict": true,
"typeRoots": ["./node_modules/@types"]
},
"include": ["server.ts"]
}