-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (45 loc) · 1.37 KB
/
server.js
File metadata and controls
55 lines (45 loc) · 1.37 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Load the express web framework module
const express = require('express');
// Load our seneca module
const seneca = require('./seneca');
// Create an instance of express
const app = express();
// Use port 3000 unless one is set in the env
const port = process.env.PORT || 3000;
// Define some HTTP routes (e.g., URLs) users can access on our server
// GET http://localhost:3000/
app.get('/', (req, res) => {
res.send('My Server is working!');
});
// GET http://localhost:3000/validate/someone@myseneca.ca
app.get('/validate/:email', (req, res) => {
const email = req.params.email;
// Return a JSON formatted response indicating that the given
// email address is valid or invalid.
res.json({
/* eslint object-shorthand: "off" */
email: email,
valid: seneca.isValidEmail(email),
});
});
// GET http://localhost:3000/format/someone
app.get('/format/:name', (req, res) => {
const name = req.params.name;
// Return a JSON formatted response with the given name
// formatted as a valid email address.
res.json({
name: name,
email: seneca.formatSenecaEmail(name),
});
});
// GET http://localhost:3000/healthcheck
app.get('/healthcheck', (req, res) => {
const uptime = process.uptime();
res.json({
uptime: uptime,
});
});
/* eslint no-console: "off" */
app.listen(port, () => {
console.log(`Server started on http://localhost:${port}`);
});