-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.ts
More file actions
53 lines (44 loc) · 1.13 KB
/
server.ts
File metadata and controls
53 lines (44 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Application, Middleware } from "https://deno.land/x/oak@v12.6.1/mod.ts"
import {
IgnorePattern,
jwtMiddleware,
} from "https://deno.land/x/oak_middleware_jwt@2.2.2/mod.ts"
import { APP_PORT } from "./config.ts"
import { getAuthToken, secretKey } from "./utils/utils.ts"
import schemaRouter from "./routes/schema.ts"
import { oakCors } from "https://deno.land/x/cors/mod.ts"
const ignorePatterns: IgnorePattern[] = [
{
path: "/",
methods: ["GET"],
},
{
path: /[a-zA-Z0-9]+/,
methods: ["GET"],
},
{
path: /^\/schemas\/[a-zA-Z0-9]+/,
methods: ["GET"],
},
]
const app = new Application()
app.use(oakCors({ origin: "*" }))
app.use(
jwtMiddleware<Middleware>({
key: secretKey,
algorithm: "HS256",
ignorePatterns,
})
)
app.use(schemaRouter.routes())
app.use(schemaRouter.allowedMethods())
// 404 page
app.use(({ response }) => {
response.status = 404
response.body = "404 Not Found"
})
app.listen({ port: Number(APP_PORT) })
console.log(`Listening on port: ${APP_PORT}...`)
// Get auth token
const { token, payload } = await getAuthToken()
console.log("Auth Token:", token, payload)