-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
94 lines (78 loc) · 2.41 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const workDraftModel = require('./dataBase');
const express = require('express');
const bodyParser = require('body-parser');
process.title = 'myApp';
/**
* http server
*/
let app = express();
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.sendfile('./src/client/views/index.html');
});
app.get('/dist/js/bundle.js', (req, res) => {
res.sendfile('./dist/js/bundle.js');
});
app.get('/dist/styles.css', (req, res) => {
res.sendfile('./dist/styles.css');
});
// get picture list
app.get('/image-list', (req, res) => {
workDraftModel.find((err, works) => {
if (err) {
console.error(err);
}
res.send(JSON.stringify(works));
});
});
app.get('/public/images/image/:id', (req, res) => {
res.sendfile('./public/images/' + req.params.id);
});
app.post('/project-list', (req, res) => {
const title = req.body.title;
let query = title ? {name: 'project', title} : {name: 'project'};
workDraftModel.find(query, (err, works) => {
if (err) {
console.error(err);
}
res.setHeader("Content-Type","application/json");
res.send(JSON.stringify(works));
});
});
app.get('/public/images/project/:id', (req, res) => {
res.sendfile('./public/images/' + req.params.id);
});
// get detail
app.get('/project/detail/:id', (req, res) => {
workDraftModel.find({_id: req.params.id}, (err, projectDetail) => {
if (err) {
console.error(err);
}
res.send(JSON.stringify(projectDetail));
});
});
// detail pictures
app.get('/detail/:projectId/:detailId', (req, res) => {
res.sendfile('./public/images/' + req.params.projectId + '-' + req.params.detailId);
});
// get single picture
app.get('/public/main-picture-01', (req, res) => {
res.sendfile('./public/images/main-01.jpg');
});
app.get('/public/main-picture-02', (req, res) => {
res.sendfile('./public/images/main-02.jpg');
});
app.get('/public/main-picture-03', (req, res) => {
res.sendfile('./public/images/main-03.jpg');
});
app.get('/public/images-01.jpeg', (req, res) => {
res.sendfile('./public/images/images-01.jpeg');
});
app.get('/public/images-big.jpg', (req, res) => {
res.sendfile('./public/images/images-big.jpg');
});
var server = app.listen(8081,function () {
var host = server.address().address;
var port = server.address().port;
console.log("server is working, visit: " + host + ":" + port);
});