This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/middleware/AuthMiddleware.ts | |
import {Request, Response, NextFunction} from "express"; | |
export function AuthMiddleware(req: Request, res: Response, next: NextFunction) { | |
if (!req.header('Authorization')) { | |
return res.status(401).send('unauthorized'); | |
} | |
next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/app.ts | |
for (const route of router) { | |
app.use(route.getPrefix(), route.getRouter()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/routes/auth.route.ts | |
constructor() { | |
super(); | |
this.prefix = '/auth'; | |
this.setRoutes(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/routes/route.ts | |
protected prefix: string = '/'; | |
public getPrefix() { | |
return this.prefix; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/app.ts | |
import express from 'express'; | |
import morgan from 'morgan'; | |
import {router} from "./router"; | |
const app: express.Application = express(); | |
app.use(morgan('dev')); | |
app.use(express.json()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/router.ts | |
import Route from "./routes/route"; | |
import AuthRoute from "./routes/auth.route"; | |
export const router: Array<Route> = [ | |
new AuthRoute(), | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/routes/auth.route.ts | |
import AuthController from "../controllers/AuthController" | |
import Route from "./route"; | |
class AuthRoute extends Route{ | |
private authController = new AuthController(); | |
constructor() { | |
super(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/routes/route.ts | |
import {Router} from "express"; | |
abstract class Route { | |
protected router = Router(); | |
protected abstract setRoutes(): void; | |
public getRouter() { | |
return this.router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/controllers/AuthController.ts | |
import {Request, Response} from "express"; | |
class AuthController { | |
echo(req: Request, res: Response) { | |
res.send('echo'); | |
} | |
} | |
export default AuthController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subscription = device.monitorCharacteristicForService( | |
Service_UUID, | |
Characteristic_UUID, | |
(error, characteristic) => { | |
if (error) { | |
console.log(error) | |
return; | |
} | |
console.log(characteristic.value) | |
} |