feat: basic code and configurations

This commit is contained in:
Riccardo
2023-07-18 21:48:58 +02:00
parent bb34d5a2b5
commit 88854532a5
17 changed files with 4807 additions and 1 deletions

9
src/call/call.test.ts Normal file
View File

@@ -0,0 +1,9 @@
import { formatResponse } from './call';
describe('call', () => {
it('returns the formatted response string', async () => {
const response = formatResponse('test');
expect(response).toBe('This is the string from GET: test');
});
});

8
src/call/call.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* Format a response message containing a user input.
* @param string - The user input string.
* @returns The formatted message.
*/
export function formatResponse(str: string) {
return `This is the string from GET: ${str}`;
}

16
src/index.ts Normal file
View File

@@ -0,0 +1,16 @@
import express, { Request, Response } from 'express';
import { formatResponse } from './call/call';
const app = express();
app.get('/', (req: Request, res: Response) => {
if (!req.query.string) {
return res.status(400).send('Missing query parameter: str');
}
return res.send(formatResponse(req.query.string as string));
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});