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
| import Axios from 'axios'; | |
| import JwtDecode from 'jwt-decode'; | |
| const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IkFiaW1ib2xhMTMwQGdtYWlsLmNvbSIsImlhdCI6MTU3MDIyMzQyNCwiZXhwIjoxNTcwMjIzNjA0fQ.fIMfLpVZOjt9W1Kk6gSippRCA8XvRsOo94jQkC1lSXE"; | |
| const axios = Axios.create({ | |
| baseURL: 'https://url.com', | |
| timeout: 80000, | |
| headers: { | |
| 'Content-Type': 'application/json', |
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 Handlers() *mux.Router { | |
| r := mux.NewRouter().StrictSlash(true) | |
| r.Use(CommonMiddleware) | |
| r.HandleFunc("/", controllers.TestAPI).Methods("GET") | |
| r.HandleFunc("/api", controllers.TestAPI).Methods("GET") | |
| r.HandleFunc("/register", controllers.CreateUser).Methods("POST") | |
| r.HandleFunc("/login", controllers.Login).Methods("POST") |
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 JwtVerify(next http.Handler) http.Handler { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| var header = r.Header.Get("x-access-token") //Grab the token from the header | |
| header = strings.TrimSpace(header) | |
| if header == "" { | |
| //Token is missing, returns with error code 403 Unauthorized | |
| w.WriteHeader(http.StatusForbidden) |
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 Login(w http.ResponseWriter, r *http.Request) { | |
| user := &models.User{} | |
| err := json.NewDecoder(r.Body).Decode(user) | |
| if err != nil { | |
| var resp = map[string]interface{}{"status": false, "message": "Invalid request"} | |
| json.NewEncoder(w).Encode(resp) | |
| return | |
| } | |
| resp := FindOne(user.Email, user.Password) | |
| json.NewEncoder(w).Encode(resp) |
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
| import ( | |
| "auth/models" | |
| "auth/utils" | |
| "encoding/json" | |
| "fmt" | |
| "net/http" | |
| "golang.org/x/crypto/bcrypt" | |
| ) |
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
| package utils | |
| import ( | |
| "auth/models" | |
| "fmt" | |
| "log" | |
| "os" | |
| "github.com/jinzhu/gorm" | |
| _ "github.com/jinzhu/gorm/dialects/postgres" //Gorm postgres dialect interface |
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
| package models | |
| import ( | |
| "github.com/jinzhu/gorm" | |
| ) | |
| //User struct declaration | |
| type User struct { | |
| gorm.Model | |
| Name string |
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 path = require('path'); | |
| const glob = require('glob'); | |
| const fs = require('fs'); | |
| const loadMetroConfig = require('@react-native-community/cli/build/tools/loadMetroConfig') | |
| .default; | |
| const loadConfig = require('@react-native-community/cli/build/tools/getLegacyConfig') | |
| .default; | |
| const Server = require('metro/src/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
| exports.scrapeTwittter = async (req, res) => { | |
| let ret = []; | |
| const { search } = req.query; | |
| try { | |
| const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }); | |
| const page = await browser.newPage(); | |
| await page.goto(`https://twitter.com/search?f=tweets&vertical=default&q=${search}&src=typd`); | |
| //set viewport for the autoscroll function | |
| await page.setViewport({ | |
| width: 1200, |
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
| exports.getNews = async (req, res) => { | |
| const { address } = req.query; | |
| const webAddress = `https://${(address || 'news.ycombinator')}.com`; | |
| try { | |
| const browser = await puppeteer.launch(); | |
| const page = await browser.newPage(); | |
| await page.goto(`${webAddress}`, { waitUntil: 'networkidle2' }); | |
| await page.pdf({ path: `./assets/news.pdf`, format: 'A4' }); |
NewerOlder