-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisten.js
More file actions
48 lines (38 loc) · 991 Bytes
/
Copy pathlisten.js
File metadata and controls
48 lines (38 loc) · 991 Bytes
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
#!/usr/bin/env node
express = require('express')
bodyparser = require('body-parser')
path = require('path')
fs = require('fs')
const testData = require('./data/testData')
app= express()
app.use(bodyparser.urlencoded({'extended': true}))
app.use(bodyparser.json());
app.use((req, res, next) => {
console.log(['req', req.method, req.path, req.params, req.query, req.body])
next()
})
app.all('/', (req, res) => {
res.send('ok\n')
})
const m2m_rt = testData.testM2MReturn
app.post('/auth/token',(req,res) => {
const body = req.body
if(body.client_secret){
return res.send(m2m_rt)
}
})
app.get('/download', (req, res) =>{
const fileName = path.join(__dirname, './nock.js')
const file = fs.readFileSync(fileName)
// res.attachment(fileName)
// res.send(file)
res.download(fileName)
})
app.all('*', (req, res) => {
console.log('other route')
res.send('ok\n')
})
const port = process.argv[2]
app.listen(port, () => {
console.log('listen at', port)
})