Skip to content

Commit cc2bdcb

Browse files
Start switch to TS
- Added new run scripts, nodemon - Removed AWS package - Added most type packages - Transformed auth middleware and login endpoint to middleware
1 parent b0e03a8 commit cc2bdcb

12 files changed

+850
-365
lines changed

index.js index.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
const express = require("express");
2-
const bodyParser = require("body-parser");
3-
const bcrypt = require('bcrypt');
4-
const cors = require('cors');
5-
require('dotenv').config();
1+
import express, { Express, Request, Response, NextFunction } from "express";
2+
import cors from 'cors';
3+
import dotenv from "dotenv";
4+
dotenv.config();
65

76
process.env.TZ = 'UTC';
87

9-
const app = express();
8+
const app: Express = express();
109

1110
app.use(cors())
12-
app.use(bodyParser.json());
13-
app.use(bodyParser.urlencoded({ extended: true }));
11+
app.use(express.json());
12+
app.use(express.urlencoded({extended:true}));
1413

1514
//Import the login router
16-
var login = require('./src/routes/login.js');
15+
import login from "./src/routes/login";
1716
app.use('/login', login);
1817

19-
app.get("/", (request, response) => {
18+
app.get("/", (request: Request, response: Response) => {
2019
const status = {
2120
Status: "Running",
2221
};
@@ -25,9 +24,17 @@ app.get("/", (request, response) => {
2524
});
2625

2726
//Import the auth middleware
28-
var auth = require('./src/middleware/token.js');
27+
import auth from "./src/middleware/auth";
2928
app.use(auth);
3029

30+
app.get("/authed", (request: Request, response: Response) => {
31+
const status = {
32+
Status: "Authed",
33+
};
34+
35+
response.send(status);
36+
});
37+
/*
3138
//------- Any routes forward need to be authorized -------
3239
var inv = require('./src/routes/invoices.js');
3340
app.use('/invoices', inv);
@@ -36,7 +43,7 @@ var clients = require('./src/routes/clients.js');
3643
app.use('/clients', clients);
3744
3845
var products = require('./src/routes/products.js');
39-
app.use('/products', products);
46+
app.use('/products', products); */
4047

4148
//Internal function for hashing passwords.
4249
/*
@@ -61,12 +68,12 @@ app.post("/pass", async (request, response) => {
6168

6269

6370
//Error Handler
64-
const jsonErrorHandler = (err, req, res, next) => {
71+
const jsonErrorHandler = (err: Error, req: Request, res: Response, next: NextFunction) => {
6572
console.log("Error: ", err);
6673
res.status(500).send({ error: err });
6774
};
6875
app.use(jsonErrorHandler);
69-
const json404Handler = (req, res, next) => {
76+
const json404Handler = (req: Request, res: Response, next: NextFunction) => {
7077
res.status(404).send({ error: "Route not found" });
7178
};
7279
app.use(json404Handler);

0 commit comments

Comments
 (0)