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 ( ) ;
6
5
7
6
process . env . TZ = 'UTC' ;
8
7
9
- const app = express ( ) ;
8
+ const app : Express = express ( ) ;
10
9
11
10
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 } ) ) ;
14
13
15
14
//Import the login router
16
- var login = require ( ' ./src/routes/login.js' ) ;
15
+ import login from " ./src/routes/login" ;
17
16
app . use ( '/login' , login ) ;
18
17
19
- app . get ( "/" , ( request , response ) => {
18
+ app . get ( "/" , ( request : Request , response : Response ) => {
20
19
const status = {
21
20
Status : "Running" ,
22
21
} ;
@@ -25,9 +24,17 @@ app.get("/", (request, response) => {
25
24
} ) ;
26
25
27
26
//Import the auth middleware
28
- var auth = require ( ' ./src/middleware/token.js' ) ;
27
+ import auth from " ./src/middleware/auth" ;
29
28
app . use ( auth ) ;
30
29
30
+ app . get ( "/authed" , ( request : Request , response : Response ) => {
31
+ const status = {
32
+ Status : "Authed" ,
33
+ } ;
34
+
35
+ response . send ( status ) ;
36
+ } ) ;
37
+ /*
31
38
//------- Any routes forward need to be authorized -------
32
39
var inv = require('./src/routes/invoices.js');
33
40
app.use('/invoices', inv);
@@ -36,7 +43,7 @@ var clients = require('./src/routes/clients.js');
36
43
app.use('/clients', clients);
37
44
38
45
var products = require('./src/routes/products.js');
39
- app . use ( '/products' , products ) ;
46
+ app.use('/products', products); */
40
47
41
48
//Internal function for hashing passwords.
42
49
/*
@@ -61,12 +68,12 @@ app.post("/pass", async (request, response) => {
61
68
62
69
63
70
//Error Handler
64
- const jsonErrorHandler = ( err , req , res , next ) => {
71
+ const jsonErrorHandler = ( err : Error , req : Request , res : Response , next : NextFunction ) => {
65
72
console . log ( "Error: " , err ) ;
66
73
res . status ( 500 ) . send ( { error : err } ) ;
67
74
} ;
68
75
app . use ( jsonErrorHandler ) ;
69
- const json404Handler = ( req , res , next ) => {
76
+ const json404Handler = ( req : Request , res : Response , next : NextFunction ) => {
70
77
res . status ( 404 ) . send ( { error : "Route not found" } ) ;
71
78
} ;
72
79
app . use ( json404Handler ) ;
0 commit comments