forked from brianloveswords/hacktionary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (28 loc) · 790 Bytes
/
Copy pathapp.js
File metadata and controls
33 lines (28 loc) · 790 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
29
30
31
32
33
var express = require('express')
, fs = require('fs')
, path = require('path');
var app = express.createServer();
var elements = JSON.parse(fs.readFileSync('./elements.json'));
app.use(express.static(path.join(__dirname, "static")));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.get('/term/html/:element', function (req, res) {
var term = req.param('element')
, thing = elements[term];
res.contentType('json');
if (thing) {
res.send({
term: term,
definition: thing,
attribution: {
license: 'CC-BY-NC',
link:'http://html5doctor.com/element-index/#' + term
}
}, 200);
} else {
res.send({term: term, definition: 'not found'}, 404);
}
});
module.exports = app;