-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (45 loc) · 1.61 KB
/
Copy pathapp.js
File metadata and controls
66 lines (45 loc) · 1.61 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
var express = require('express');
var app = express();
//var port = process.env.PORT || 3000;
var fs = require( 'fs' );
var ejs = require( 'ejs' );
app.engine('ejs',ejs.renderFile);
//サーバーの立ち上げ
var http = require('http');
var cfenv = require( 'cfenv' );
var appEnv = cfenv.getAppEnv();
app.use(express.static(__dirname + '/public'));
//body-parser
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//指定したポートにきたリクエストを受け取れるようにする
var server = http.createServer(app).listen(appEnv.port, function () {
console.log('Server listening at port %d', appEnv.port);
});
app.get('/', function(req, res){
var template = fs.readFileSync(__dirname + '/public/index.ejs', 'utf-8');
var data = ejs.render(template, {});
res.writeHead(200, { 'Content-Type': 'text/html' } );
res.write(data);
res.end();
});
app.get('/tree', function(req, res){
var template = fs.readFileSync(__dirname + '/public/tree/index.ejs', 'utf-8');
var data = ejs.render(template, {});
res.writeHead( 200, { 'Content-Type': 'text/html' } );
res.write(data);
res.end();
});
app.use('/getTreeData', require('./routes/getTreeData'));
app.use('/insertDB', require('./routes/insertDB'));
//app.use('/upload',require('./routes/upload.js'))
app.get('/tree/play', function(req, res){
var template = fs.readFileSync(__dirname + '/public/tree/play.ejs', 'utf-8');
var data = ejs.render(template, {});
res.writeHead( 200, { 'Content-Type': 'text/html' } );
res.write(data);
res.end();
});
app.listen(server);