-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (42 loc) · 1.33 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
51
52
53
54
55
56
//Lets require/import the HTTP module
var http = require('http'),
fs = require('fs'),
express = require("express"),
app = express(),
path = require("path"),
xml = require('xml');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
app.get('/',function(req,res){
res.sendFile(path.join(__dirname +'/home.html'));
});
app.get('/canvas_out',function(req,res){
res.sendFile(path.join(__dirname +'/canvas_out.html'))
});
app.get('/get_components', function(req,res) {
var style = req.query.type;
var dir = 'assets/images/svg/' + style + '/';
var array = [];
var files = fs.readdirSync(dir);
files.forEach(function(file) {
array.push(file);
});
res.send(array);
});
app.get('/canvas_in',function(req,res){
res.sendFile(path.join(__dirname +'/canvas_in.html'));
});
app.use(express.static(__dirname + '/assets'));
app.listen(3000);
console.log("Running at Port 3000");