forked from mozilla/popcorn-js
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathserver.js
50 lines (42 loc) · 1.04 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
42
43
44
45
46
47
48
49
50
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/'));
var port = 8000;
/*
* Get method for testing purposes.
*
* It replaces old /test/data/method.php
*/
app.get('/test/method', function (req, res) {
res.send('{ "method": "get" }');
});
/*
* Post method for testing purposes.
*
* It replaces old /test/data/method.php
*/
app.post('/test/method', function (req, res) {
res.send('{ "method": "post" }');
});
/*
* Get method for testing purposes.
*
* It replaces old /test/data/jsonp.php
*/
app.get('/test/jsonp', function (req, res) {
res.send(req.query.callback + '({ "data": {"lang": "en", "length": 25} });');
});
/*
* Get method for testing purposes.
*
* It replaces old /test/data/jsonpfancyapi.php
*/
app.get('/test/jsonpfancyapi', function (req, res) {
var callback = req.questy.callback;
if (!callback) {
res.send('Invalid Parameter');
} else {
res.send(callback + '({ "data": {"lang": "en", "length": 25} });');
}
});
app.listen(port);