Skip to content

Instantly share code, notes, and snippets.

View nidhi-canopas's full-sized avatar

nidhi-canopas

View GitHub Profile
async function invokeAPI() {
await fetch('http://localhost:3000/ping')
.then(res => {
for (var headers of res.headers.entries()) {
console.log(headers[0]+ ': '+ headers[1]);
}
})
}
const express = require('express')
const app = express()
const cors = require('cors')
const port = 3000
app.use(cors(
{
exposedHeaders: ['token'],
}
const cors = require('cors')
app.use(cors())
<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')
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}`)
if inLambda() {
fmt.Println("running aws lambda in aws")
lambda.Start(YourCode)
} else {
fmt.Println("running aws lambda in local")
YourCode()
}
func inLambda() bool {
if lambdaTaskRoot := os.Getenv("LAMBDA_TASK_ROOT"); lambdaTaskRoot != "" {
return true
}
return false
}
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:)")
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 {
// 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!")