-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (44 loc) · 1.36 KB
/
server.js
File metadata and controls
54 lines (44 loc) · 1.36 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
// Load the express web framework module
var express = require('express');
// Load our seneca module
var seneca = require('./seneca');
// Create an instance of express
var app = express();
// Use port 3000 unless one is set in the env
var port = process.env.PORT || 3000;
// Define some HTTP routes (e.g., URLs) users can access on our server
// GET http://localhost:3000/
app.get('/', function (req, res) {
res.send('My Server is working!');
});
//GET http://localhost:3000/healthcheck
app.get('/healthcheck/', function (req, res) {
var processUptime = process.uptime();
res.json({
uptime: processUptime,
});
});
// GET http://localhost:3000/validate/someone@myseneca.ca
app.get('/validate/:email', function (req, res) {
var email = req.params.email;
// Return a JSON formatted response indicating that the given
// email address is valid or invalid.
res.json({
email: email,
valid: seneca.isValidEmail(email)
});
});
// GET http://localhost:3000/format/someone
app.get('/format/:name', function (req, res) {
var 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)
});
});
// Start our web server on port 3000
app.listen(port, function () {
console.log('Server started on http://localhost:' + port);
});