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
| async function invokeAPI() { | |
| await fetch('http://localhost:3000/ping') | |
| .then(res => { | |
| for (var headers of res.headers.entries()) { | |
| console.log(headers[0]+ ': '+ headers[1]); | |
| } | |
| }) | |
| } |
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 app = express() | |
| const cors = require('cors') | |
| const port = 3000 | |
| app.use(cors( | |
| { | |
| exposedHeaders: ['token'], | |
| } |
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 cors = require('cors') | |
| app.use(cors()) |
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
| <html> | |
| <head> | |
| <title>Demo</title> | |
| </head> | |
| <body> | |
| <p>Welcome to CORS demo</p> | |
| <script type="text/javascript"> | |
| async function invokeAPI() { | |
| var result = await fetch('http://localhost:3000/ping') |
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 app = express() | |
| const port = 3000 | |
| app.get('/ping', (req, res) => { | |
| res.send('Pong!') | |
| }) | |
| app.listen(port, () => { | |
| console.log(`Example app listening on port ${port}`) |
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
| if inLambda() { | |
| fmt.Println("running aws lambda in aws") | |
| lambda.Start(YourCode) | |
| } else { | |
| fmt.Println("running aws lambda in local") | |
| YourCode() | |
| } |
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
| func inLambda() bool { | |
| if lambdaTaskRoot := os.Getenv("LAMBDA_TASK_ROOT"); lambdaTaskRoot != "" { | |
| return true | |
| } | |
| return false | |
| } |
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
| ref := client.NewRef("user_scores/1") | |
| if err := ref.Delete(context.TODO()); err != nil { | |
| log.Fatalln("error in deleting ref: ", err) | |
| } | |
| fmt.Println("user's score deleted successfully:)") |
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
| type UserScore struct { | |
| Score int `json:"score"` | |
| } | |
| // get database reference to user score | |
| ref := client.NewRef("user_scores/1") | |
| // read from user_scores using ref | |
| var s UserScore | |
| if err := ref.Get(context.TODO(), &s); err != nil { |
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
| // create ref at path user_scores/:userId | |
| ref := client.NewRef("user_scores/" + fmt.Sprint(1)) | |
| if err := ref.Set(context.TODO(), map[string]interface{}{"score": 40}); err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Println("score added/updated successfully!") |
NewerOlder