-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (22 loc) · 923 Bytes
/
Copy pathserver.js
File metadata and controls
28 lines (22 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const express = require('express');
// Constants
const PORT = 3000;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello remote world!\n');
});
// New endpoint: GET /hello?name=YOUR_NAME -> "hello YOUR_NAME"
app.get('/hello', (req, res) => {
const nameParam = req.query && typeof req.query.name === 'string' ? req.query.name.trim() : '';
const name = nameParam.length > 0 ? nameParam : 'world';
res.send(`hello ${name}\n`);
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);