forked from angular-translate/angular-translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_routes.js
42 lines (35 loc) · 1.06 KB
/
server_routes.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
module.exports = function (app, dir) {
var url = require('url'), fs = require('fs');
app.get('/demo/', function(req, res) {
function answer(code, data) {
res.writeHead(code,{
'Content-Type':'text/html;charset=utf-8'
});
res.end(data);
};
var _get = url.parse(req.url, true).query;
fs.readFile('./demo/index.htm', function(err, data) {
if (err) answer(404, '');
else answer(200, data);
});
});
app.get('/demo/get_lang', function (req, res) {
function answer(code, data) {
res.writeHead(code,{
'Content-Type':'application/json;charset=utf-8',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Headers':'X-Requested-With'
});
res.end(data);
};
var _get = url.parse(req.url, true).query;
fs.readFile('./demo/l10n/' + _get['lang'] + '.json', function(err, data) {
if (err) answer(404, '');
else answer(200, data);
});
});
// Example
app.get('/this-is-an-express-server', function (req, res) {
res.send(200);
});
};