You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
import express = require("express")
|
|
import { ApolloServer } from "apollo-server-express"
|
|
import { createSchema } from "./server/schema"
|
|
import {
|
|
accessTokenWithRefreshCookie,
|
|
contextFunction,
|
|
verifiedRefreshTokenPayload,
|
|
} from "./server/userResolver/auth"
|
|
import cookie = require("cookie")
|
|
|
|
export const createServer = async (port: number) => {
|
|
const server = new ApolloServer({
|
|
schema: await createSchema(),
|
|
playground: true,
|
|
introspection: true,
|
|
debug: true,
|
|
context: contextFunction,
|
|
})
|
|
|
|
const app = express()
|
|
app.post("/refresh_token", (req, res) => {
|
|
try {
|
|
const parsedCookie = cookie.parse(req.headers.cookie!)
|
|
const refreshPayload = verifiedRefreshTokenPayload(parsedCookie.rt)
|
|
const accessToken = accessTokenWithRefreshCookie(refreshPayload.userId, res)
|
|
res.json({ data: accessToken })
|
|
} catch (error) {
|
|
res.json({ data: null, errors: "Refresh failed: " + error })
|
|
}
|
|
})
|
|
server.applyMiddleware({ app })
|
|
app.listen({ port })
|
|
|
|
return server
|
|
}
|
|
|