🐘👽 Checkpoint

./public/script.js:1954897/2956
./server.js:1954897/2812
This commit is contained in:
Glitch (tabu) committed 2019-07-01 12:18:06 +00:00
1 parent 6646907e85
commit e3ca0b8030
2 files changed
+33 -22

No files matched your search

+24 -13
View File
@@ -1,22 +1,33 @@
// server.js
// where your node app starts
// init project
const express = require('express');
const app = express();
const palabras = require('./palabras.js')
// we've started you off with Express,
// but feel free to use whatever libs or frameworks you'd like through `package.json`.
// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));
// http://expressjs.com/en/starter/basic-routing.html
app.get('/', function(request, response) {
response.sendFile(__dirname + '/views/index.html');
app.get('/', function (req, res) {
res.sendFile(__dirname + '/views/index.html');
});
app.get('/palabras.json', function (req, res) {
res.json({
words: getRandom(palabras, 10)
})
});
// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
console.log('Your app is listening on port ' + listener.address().port);
});
function getRandom(arr, n) {
var result = new Array(n)
, len = arr.length
, taken = new Array(len)
;
if (n > len) {
throw new RangeError("getRandom: more elements taken than available");
} while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}