-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 1 KB
/
server.js
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
// Load Express framework
var express = require("express");
var app = express();
// Load Uniform
var validator = require("uniform-validation");
// Serve the www/ directory to clients
app.use(express.static("www"));
// Serve the client-side library to /uniform.js
app.get("/uniform.js", function (req, res) {
validator.getClientLib().then(function (lib) {
res.end(lib);
});
});
// On POST to /submit, validate with Uniform
app.post("/submit", validator("www/car.ufm"), function (req, res) {
var result = req.ufmResult;
var output;
if (!result.hasCar) {
output = "User does not own a car."
} else {
var car = result.car;
output = "User owns a " + car.myYear + " " + car.myMake
+ " " + car.myModel + ".";
}
console.log(output);
res.end("Valid :)");
}, function (err, req, res, next) {
res.end("Invalid :(");
console.error(err);
});
// Listen on port 8000
app.listen(8000, function () {
console.log("Started server. View it at http://localhost:8000");
});