From 061e96a9dc805d09106366735553c0dbe5dc9e29 Mon Sep 17 00:00:00 2001 From: ZedBee27 <101090381+ZedBee27@users.noreply.github.com> Date: Thu, 23 Nov 2023 00:31:16 +0500 Subject: [PATCH] Add files via upload --- index.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 index.ts diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..22d734a --- /dev/null +++ b/index.ts @@ -0,0 +1,38 @@ +// src/index.ts +import express, { Request, Response } from 'express'; +import cors from 'cors'; + + +const app = express(); +const port = 3000; + +app.get('/', (req: Request, res: Response) => { + res.send('Hello, TypeScript with Express!'); +}); + +// Use CORS middleware +app.use(cors()); + + +app.listen(port, () => { + console.log(`Server is running at http://localhost:${port}`); +}); + +// New API endpoint +app.get('/awesome/applicant', (req: Request, res: Response) => { + const myInfo = { + name: 'Zubia', + role: 'Student', + funFact: 'I love coding', + }; + + res.json(myInfo); +}); + +app.use(cors({ + origin: 'http://localhost:3000', +})); + +app.listen(port, () => { + console.log(`Server is running at http://localhost:${port}`); +});