This file contains 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 { 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(); |
This file contains 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 { 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!"); |
This file contains 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 { 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"; |
This file contains 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 { 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) |
This file contains 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 { 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; |
This file contains 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 { 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; |
This file contains 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 { 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(); |
This file contains 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
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); | |
} |
This file contains 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
let globalThis = this; | |
function func1() { | |
console.log('Global This: ', globalThis); | |
console.log('Local This: ', this); | |
console.log('Are they same?', globalThis === this); | |
} | |
func1() |