-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
80 lines (59 loc) · 1.69 KB
/
server.js
File metadata and controls
80 lines (59 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
var demoJsonResolve = require.resolve('./constant/demos.json')
var app = require('express')();
var http = require('http').Server(app);
var maxDemoIndex = require('./constant/demos.json').max_demo_index
var path = require('path');
var indexHTML = path.join(__dirname, 'index.html');
var indexScript = path.join(__dirname, 'js', 'index.js');
var demosJson = path.join(__dirname, 'constant', 'demos.json');
var styleCSS = path.join(__dirname, 'css', 'style.css');
var demoPreProcessed = path.join(__dirname, 'js', 'preProcessedDemo.js');
app.get(/^\/ext\/(.*)$/, function(req, res) {
res.sendFile(path.join(__dirname, 'ext', req.params[0]));
});
app.get(/^\/(\d+)\/$/, function(req, res) {
res.sendFile(indexHTML);
});
app.get('/script.js', function(req, res) {
res.sendFile(indexScript);
});
app.get('/style.css', function(req, res) {
res.sendFile(styleCSS);
});
app.get('/demos.json', function(req, res) {
res.sendFile(demosJson);
});
app.get(/^\/(\d+)\/demo.js$/, function(req, res) {
var demoIdx = parseInt(req.params[0]);
var scriptName = demoIdx >= maxDemoIndex ? 'lastDemo' :
'demo_' + demoIdx;
res.sendFile(path.join(__dirname, 'js/' + scriptName + '.js'));
});
app.get('/preProcessedDemo.js', function(req, res) {
res.sendFile(demoPreProcessed);
});
app.get('/getUser', function(req, res) {
setTimeout(function() {
res.json({
userId: 3
});
}, 2500);
});
app.get('/getProfile', function(req, res) {
setTimeout(function() {
res.json({
foto: null
});
}, 2500);
});
app.get('/getTweets', function(req, res) {
setTimeout(function() {
res.json({
tweets: []
});
}, 2500);
});
http.listen(3000, function() {
console.log('listening on *:3000');
});