Skip to content

Commit

Permalink
Merge pull request #132 from sebringrose/sitemaps
Browse files Browse the repository at this point in the history
fix: examples
  • Loading branch information
sejori authored Feb 21, 2023
2 parents c73223b + 9227c96 commit 2aa9935
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions examples/auth/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const validateUser = async (username: string, password: string) => {

// generate JWT
server.addRoute({
route: "/login",
path: "/login",
method: "POST",
handler: async (ctx) => {
const { username, password } = await ctx.request.json()
Expand Down Expand Up @@ -50,14 +50,14 @@ server.addRoute({

// verify JWT in auth middleware
server.addRoute({
route: "/authTest",
path: "/authTest",
middleware: Peko.authenticator(crypto),
handler: () => new Response("You are authenticated!")
})

// basic HTML page with buttons to call auth routes
server.addRoute({
route: "/",
path: "/",
handler: Peko.ssrHandler(() => `<!doctype html>
<html lang="en">
<head>
Expand Down
2 changes: 1 addition & 1 deletion examples/preact/routes/APIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

export const APIs: Route[] = [
{
route: "/api/parrot",
path: "/api/parrot",
method: "POST",
handler: async (ctx: RequestContext) => {
const body = await ctx.request.text()
Expand Down
2 changes: 1 addition & 1 deletion examples/preact/routes/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const assets: Route[] = filenames.map(file => {
const fileRoute = file.slice(file.lastIndexOf("/src/" ) + 5)

return {
route: `/${fileRoute}`,
path: `/${fileRoute}`,
middleware: env.ENVIRONMENT === "production" ? cacher(cache) : [],
handler: staticHandler(new URL(`../src/${fileRoute}`, import.meta.url), {
headers: new Headers({
Expand Down
4 changes: 2 additions & 2 deletions examples/preact/routes/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const env = Deno.env.toObject()

export const pages: Route[] = [
{
route: "/",
path: "/",
// use cacher to serve responses from cache in prod env
middleware: env.ENVIRONMENT === "production" ? cacher(cache) : [],
handler: ssrHandler(() => {
Expand Down Expand Up @@ -45,7 +45,7 @@ export const pages: Route[] = [
})
},
{
route: "/about",
path: "/about",
middleware: [
(ctx) => {
ctx.state = {
Expand Down
4 changes: 2 additions & 2 deletions examples/sse/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ setInterval(() => {

// SSE route streams data from testEmitter
server.addRoute({
route: "/sse",
path: "/sse",
handler: sseHandler(demoEventTarget)
})

// adjust home page handler templating to include EventSource connection logic
pages[0].handler = ssrHandler((ctx) => {
const appHTML = renderToString(Home(ctx.state), null, null)
const appHTML = renderToString(Home(), null, null)
return htmlTemplate({
appHTML,
title: `<title>Peko</title>`,
Expand Down
17 changes: 10 additions & 7 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
*/

// Core classes, functions & types
import Server from "./server.ts"
export default Server
export * from "./server.ts"
export * from "./types.ts"

// Handlers
export * from "./handlers/static.ts"
export * from "./handlers/ssr.ts"
export * from "./handlers/sse.ts"

// Middlewares
export * from "./middleware/authenticator.ts"
export * from "./middleware/cacher.ts"
export * from "./middleware/logger.ts"
export * from "./middleware/cacher.ts"
export * from "./middleware/authenticator.ts"

// Utils
export * from "./utils/Crypto.ts"
export * from "./utils/ResponseCache.ts"
export * from "./utils/Router.ts"
export * from "./utils/Cascade.ts"
export * from "./utils/helpers.ts"
export * from "./utils/ResponseCache.ts"
export * from "./utils/Crypto.ts"
export * from "./utils/helpers.ts"

import { Server } from "./server.ts"
export default Server
4 changes: 1 addition & 3 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,4 @@ export class Server extends Router {
close(): void {
if (this.stdServer) this.stdServer.close()
}
}

export default Server
}
2 changes: 1 addition & 1 deletion tests/scripts/profile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Server from "../../server.ts"
import { Server } from "../../server.ts"
import {
testMiddleware2,
testMiddleware3,
Expand Down
2 changes: 1 addition & 1 deletion tests/server_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Server from "../server.ts"
import { Server } from "../server.ts"
import {
testMiddleware2,
testMiddleware3,
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/Cascade_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ Deno.test("UTIL: Cascade", async (t) => {
(testContext.state.middleware3 as { end: number }).end
)
})

// TODO: test post response ops don't block serving request
})
2 changes: 1 addition & 1 deletion tests/utils/Profiler_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from "https://deno.land/std@0.174.0/testing/asserts.ts"
import Server from "../../server.ts"
import { Server } from "../../server.ts"
import Profiler from "../../utils/Profiler.ts"

Deno.test("UTIL: Profiler", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/helpers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Deno.test("UTIL: helpers", async (t) => {
assert(text === "I was set")
})

// sitemap test
// TODO: sitemap test
})
2 changes: 1 addition & 1 deletion utils/Profiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Server from "../server.ts"
import { Server } from "../server.ts"
import { Route } from "../types.ts"

type ProfileConfig = {
Expand Down
1 change: 1 addition & 0 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const staticDir = async (dirUrl: URL, middleware?: Middleware | Middlewar
return routes
}

// TODO: sitemap generator
// export const generateSitemap = (server: Server) => {
// return server.allRoutes.map(route => {
// // some custom sitemap object in here
Expand Down

0 comments on commit 2aa9935

Please sign in to comment.