Skip to content

Instantly share code, notes, and snippets.

View fhsinchy's full-sized avatar
🎯
Trying to focus

Farhan Hasin Chowdhury fhsinchy

🎯
Trying to focus
View GitHub Profile
import { Application, Router, Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import logger from "./middleware/logger.ts";
import timer from "./middleware/timer.ts";
import blogs from "./routes/blogs.ts";
const app = new Application();
const router = new Router();
import { isHttpError, Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
export default async (ctx: any, next: any) => {
try {
await next();
const status = ctx.response.status || Status.NotFound;
if (status === Status.NotFound) {
ctx.throw(Status.NotFound, "Not Found!");
import { Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import { slugify } from "https://deno.land/x/slugify@0.3.0/mod.ts";
import client from "../db/mysql.ts";
export async function index(ctx: any) {
const blogs: any = (await client.execute("SELECT * FROM blogs")).rows;
ctx.response.status = Status.OK;
ctx.response.type = "json";
import { Router } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import { index, show, store, update, destroy } from "../controllers/blogs.ts";
const router = new Router();
router.get("/blogs", index)
.post("/blogs", store)
.get("/blogs/:slug", show)
.put("/blogs/:slug", update)
import { Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import { hash, compare } from "https://deno.land/x/bcrypt@v0.2.4/mod.ts";
import { create, Header, Payload } from "https://deno.land/x/djwt@v2.2/mod.ts";
import client from "../db/mysql.ts";
export async function register(ctx: any) {
const body = await ctx.request.body();
const name = body.value.name;
import { Router } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import { register, login } from "../controllers/auth.ts";
const router = new Router();
router.post("/auth/register", register)
.post("/auth/login", login);
export default router;
import { Application, Router, Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import logger from "./middleware/logger.ts";
import timer from "./middleware/timer.ts";
import error from "./middleware/error.ts";
import blogs from "./routes/blogs.ts";
import auth from "./routes/auth.ts";
const app = new Application();
import { Status } from "https://deno.land/x/oak@v6.5.0/mod.ts";
import { verify } from "https://deno.land/x/djwt@v2.2/mod.ts";
export default async (ctx: any, next: any) => {
const authHeader = ctx.request.headers.get("authorization");
if (!authHeader) {
ctx.throw(Status.Unauthorized, "Access Token Missing!");
} else {
const token = authHeader.split(" ")[1];
let globalThis = this;
function func1() {
let num = 5;
console.log(`num: ${num}`);
console.log('Global This: ', globalThis);
console.log('Local This: ', this);
console.log('Are they same?', globalThis === this);
}
let globalThis = this;
function func1() {
console.log('Global This: ', globalThis);
console.log('Local This: ', this);
console.log('Are they same?', globalThis === this);
}
func1()