feat: basic code and configurations
This commit is contained in:
9
src/call/call.test.ts
Normal file
9
src/call/call.test.ts
Normal 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
8
src/call/call.ts
Normal 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
16
src/index.ts
Normal 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');
|
||||
});
|
||||
Reference in New Issue
Block a user