diff options
| author | bvdoord <bvdoord@sogyo.nl> | 2019-06-13 08:19:25 +0200 |
|---|---|---|
| committer | bvdoord <bvdoord@sogyo.nl> | 2019-06-13 08:19:25 +0200 |
| commit | cc75cd4000361bec16ff7400acf8ef1bb00908df (patch) | |
| tree | 0d94c9564c9f62c4590526925c02a47865bdb967 /main.js | |
| parent | b0772f294388217234ac200a678b932ff85f65a2 (diff) | |
Weer net iets andere uitleg
Diffstat (limited to 'main.js')
| -rw-r--r-- | main.js | 55 |
1 files changed, 45 insertions, 10 deletions
@@ -1,10 +1,24 @@ +/** + * Server side code using the express framework running on a Node.js server. + * + * Load the express framework and create an app. + */ const express = require('express'); const app = express(); -/** Host alle bestanden in de client folder als static resources */ +/** + * Host all files in the client folder as static resources. + * That means: localhost:8080/someFileName.js corresponds to client/someFileName.js. + */ app.use(express.static('client')); +/** + * Allow express to understand json serialization. + */ app.use(express.json()); +/** + * Our code starts here. + */ const attractions = [ { name: "De Efteling", @@ -91,29 +105,50 @@ const attractions = [ }, ] -app.post("/api/attractions", (request, response) => { +/** + * A route is like a method call. It has a name, some parameters and some return value. + * + * Name: /api/attractions + * Parameters: the request as made by the browser + * Return value: the list of attractions defined above as JSON + * + * In addition to this, it has a HTTP method: GET, POST, PUT, DELETE + * + * Whenever we make a request to our server, + * the Express framework will call one of the methods defined here. + * These are just regular functions. You can edit, expand or rewrite the code here as needed. + */ +app.get("/api/attractions", function (request, response) { console.log("Api call received for /attractions"); - response.json(attractions) -}) -app.post("/api/tickets", (request, response) => { - console.log("Api call received for /placeorder"); response.json(attractions) -}) +}); -app.post("/api/placeorder", (request, response) => { +app.post("/api/placeorder", function (request, response) { console.log("Api call received for /placeorder"); + + /** + * Send the status code 200 back to the clients browser. + * This means OK. + */ response.sendStatus(200); }); -app.get("/api/myorders", (request, response) => { +app.get("/api/myorders", function (request, response) { console.log("Api call received for /myorders"); + response.sendStatus(200); }); -app.get("/api/admin/edit", (request, response) => { +app.get("/api/admin/edit", function (request, response) { console.log("Api call received for /admin/edit"); + response.sendStatus(200); }); + +/** + * Make our webserver available on port 8000. + * Visit localhost:8000 in any browser to see your site! + */ app.listen(8000, () => console.log('Example app listening on port 8000!'));
\ No newline at end of file |
