Skip to content

Instantly share code, notes, and snippets.

View enesakar's full-sized avatar

Enes Akar enesakar

View GitHub Profile
import { Redis } from "@upstash/redis/cloudflare";
import { MultiRegionRatelimit } from "@upstash/ratelimit";
export interface Env {
}
const cache = new Map();
export default {
async fetch(
'use strict';
const fetch = require('node-fetch');
const assert = require('assert');
const helper = require('../helper');
var {
serverAddress,
headers
} = require('../config');
export default function handler(req, res) {
fetch("https://full-mantis-14289-us1-rest-kafka.upstash.io/produce/newtopic/MESSAGE", {
headers: {
Authorization: "Basic Wm5Wc2JDMXRZVzUwYVhNdE1UUXlPVDlUR2szT0ZkabXRvYWxYbm9ldTlUalFG5qZlNLd1X3lBcTRUUEdkOWM2SmJxZlE9PQ=="
}
}).then(response => response.json())
.then(data => {
console.log(data)
});
import { parse } from 'cookie'
import { auth, dbsize, get, setex } from '@upstash/redis'
auth(UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN)
addEventListener('fetch', (event) => {
event.respondWith(
handleRequest(event.request).catch(
import logo from './logo.svg';
import './App.css';
import {ToastContainer, toast} from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import {useEffect} from "react";
function App() {
useEffect(() => {
async function fetchData() {
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import {useEffect, useState} from "react";
export default function Home() {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [todo, setTodo] = useState("");
let changeHandler = (event) => {
var express = require('express')
var parseurl = require('parseurl')
var session = require('express-session')
const redis = require('redis')
var RedisStore = require('connect-redis')(session)
var client = redis.createClient ({
// REPLACE HERE
});
const Redis = require("ioredis");
require('dotenv').config()
console.log("EDGE analytics with CloudFlare Workers and Upstash Redis.")
let redis = new Redis(process.env.REDIS_URL);
let dateArg = process.argv[2]
let datestr;
if (dateArg) {
datestr = dateArg;
} else {
let d = new Date();
@enesakar
enesakar / aa.js
Last active June 16, 2021 03:38
aa.js
const endpoint = 'REPLACE_UPSTASH_REST_ENDPOINT'
const token = 'REPLACE_UPSTASH_REST_TOKEN'
async function recordRequest(request) {
let d = new Date();
let datestr = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
let data = [["url", request.url], ...request.headers]
let url = endpoint + '/lpush/' + datestr
const init = {
body: JSON.stringify(data),
/*
* Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software