Created
August 1, 2021 22:00
-
-
Save koraytugay/a37416fb2ecfedc3d7cde7f4d4edce99 to your computer and use it in GitHub Desktop.
Express Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Page Title</title> | |
| <style> | |
| .photoContainer { | |
| margin: 10px | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="container" style="padding: 20px"> | |
| <div id="loading">Loading..</div> | |
| </div> | |
| <script> | |
| window.onload = () => { | |
| searchFlickr(); | |
| } | |
| async function searchFlickr() { | |
| let response = await fetch("http://127.0.0.1:9999/api/posts"); | |
| let data = await response.json(); | |
| console.log(data); | |
| } | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express') | |
| const POSTS = { | |
| '1': { | |
| 'post': 'This is the first blog post.' | |
| }, | |
| '2': { | |
| 'post': 'This is the second blog post.' | |
| }, | |
| '3': { | |
| 'post': 'This is the second blog post.' | |
| } | |
| } | |
| const SERVER_PORT = 9999; | |
| const serverApp = express(); | |
| serverApp.use(express.static(__dirname)); | |
| serverApp.get('/api/posts', function(req, resp) { | |
| resp.json(POSTS); | |
| }) | |
| serverApp.listen(SERVER_PORT, function() { | |
| console.log('Started server at http://127.0.0.1:' + SERVER_PORT); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment