From d8faebc71e9d86c5d9fedab3c6d3bc1521ce2d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chif.gergo@kszk.bme.hu> Date: Mon, 9 Mar 2020 22:55:24 +0100 Subject: [PATCH] Fix declaration errors --- nodemon.json | 2 +- src/index.ts | 52 ++++++++++++++++++++++++++++++++------------------- tsconfig.json | 10 +++++----- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/nodemon.json b/nodemon.json index 70a9d667..2220bb3e 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,5 +2,5 @@ "watch": ["src"], "ext": "ts", "ignore": ["src/public"], - "exec": "ts-node src/index.ts" + "exec": "ts-node --files src/index.ts" } diff --git a/src/index.ts b/src/index.ts index ff0948f1..a857d9b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,34 +1,48 @@ -import "./utils/env" +import "./utils/env"; import express, { Request, Response, NextFunction, Application } from "express"; import mongoose from "mongoose"; import bodyParser from "body-parser"; import expressSession from "express-session"; -import authRoute from './routes/auth'; -import newsRoute from './routes/news'; - -mongoose.connect('mongodb://localhost:27017/bodysch', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true } ).then( - () => { console.log("Connected to database") }, -).catch(err => { - console.log("MongoDB connection error. Please make sure MongoDB is running. " + err); - // process.exit(); -}); +import authRoute from "./routes/auth"; +import newsRoute from "./routes/news"; + +mongoose + .connect("mongodb://localhost:27017/bodysch", { + useNewUrlParser: true, + useCreateIndex: true, + useUnifiedTopology: true + }) + .then(() => { + console.log("Connected to database"); + }) + .catch(err => { + console.log( + "MongoDB connection error. Please make sure MongoDB is running. " + err + ); + // process.exit(); + }); const app: Application = express(); app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded -app.use(expressSession({ - secret: process.env.SESSION_SECRET || "alma", - resave: false, - saveUninitialized: true, - cookie: { secure: false } -})); +app.use( + expressSession({ + secret: process.env.SESSION_SECRET || "alma", + resave: false, + saveUninitialized: true, + cookie: { secure: false } + }) +); +app.use((req: Request, res: Response, next: NextFunction) => { + res.data = {}; + next(); +}); app.get("/", (req: Request, res: Response) => { let message = "World!"; - if(req.session!.user) - message = req.session!.user!.sn || "World!"; - res.send( "Hello " + message) + if (req.session!.user) message = req.session!.user!.sn || "World!"; + res.send("Hello " + message); }); // Register routes diff --git a/tsconfig.json b/tsconfig.json index 415f62b2..69ae72cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,8 @@ { + "files": [ + "./src/utils/declarations/response.d.ts", + "./src/utils/declarations/request.d.ts" + ], "compilerOptions": { "module": "commonjs", "strict": true, @@ -15,9 +19,5 @@ "typeRoots": ["node_modules/@types"] }, "include": ["./src/**/*.ts"], - "exclude": ["./src/public/"], - "files": [ - "./src/utils/declarations/response.d.ts", - "./src/utils/declarations/request.d.ts" - ] + "exclude": ["./src/public/"] } -- GitLab