generated from comp426-2022-spring/a03
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (38 loc) · 1.26 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
//import express from 'express'
//import flip from './flip.js'
//import flips from './flips.js'
//import guess from './guess-flip.js'
const express = require('express')
const minimist = require('minimist')
const flip = require('./flip.js')
const flips = require('./flips.js')
const guess = require('./guess-flip.js')
const app = express()
var args = minimist(process.argv.slice(2))
var port = args.port
const HTTP_PORT = port||5000;
// Start an app server
const server = app.listen(HTTP_PORT, () => {
console.log('App listening on port %PORT%'.replace('%PORT%',HTTP_PORT))
});
app.get('/app/', (req, res) => {
// Respond with status 200
res.statusCode = 200;
// Respond with status message "OK"
res.statusMessage = 'OK';
res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' });
res.end(res.statusCode+ ' ' +res.statusMessage)
});
app.get('/app/flip', (req, res) => {
res.json(flip());
});
app.get('/app/flips/:number', (req, res) => {
res.json(flips(req.params.number));
});
app.get('/app/flip/call/:callcall', (req, res) => {
res.json(guess(req.params.callcall));
});
// Default response for any other request
app.use(function(req, res){
res.status(404).send('404 NOT FOUND')
});