-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_click.js
More file actions
66 lines (52 loc) · 1.68 KB
/
server_click.js
File metadata and controls
66 lines (52 loc) · 1.68 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
console.log('Server-side code running');
const express = require('express');
// const http = require('http');
const path = require('path');
const fs = require('fs');
const app = express();
// serve files from the public directory
app.use(express.static('public'));
// app.use(express.static('images'));
// start the express web server listening on 8080
app.listen(8080, '192.168.1.127', () => {
console.log('listening on 8080');
});
// serve the homepage
app.get('/', (req, res) => {
res.sendFile(__dirname + '/jq.html');
});
app.use(express.json());
app.post('/josh', (req, res) => {
console.log('Yo Josh');
console.log(req.body);
})
app.get('/imgdl', (req, res) => {
console.log('Someone is downloading the prize');
// res.writeHead(200, {
// 'Content-Type': 'image/jpeg'
// });
// const image = path.join( path.dirname(require.main.filename), 'images', 'img1.jpeg' );
res.sendFile(path.join(__dirname, 'images/img1.jpeg'));
// const image = 'images/img1.jpeg';
// const readStream = fs.createReadStream(image);
// return readStream.pipe(res);
})
app.post('/', (req, res) => {
console.log('Hi!');
});
app.post('/formrecv_post', (req, res) => {
console.log('Submitted form with POST');
res.send('Thank you for submitting with POST, we will review soon!');
})
app.get('/formrecv_get', (req, res) => {
console.log('Submitted form with GET');
res.send('Thank you for submitting with GET, we will review soon!');
})
app.post('/page', function (req, res) {
// calling.aFunction();
res.send('A message!');
console.log('Got a message from client!');
});
app.get('/images/img1.jpg', function (req, res) {
res.sendFile(path.join(__dirname, 'images/img1.jpg'));
})