Second frontend, written in Next.JS + Typescript.
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.
 
 
 

74 lines
1.4 KiB

import getConfig from "next/config";
import * as jwt from "jsonwebtoken";
class Config {
private data : ConfigData | null;
constructor(data: ConfigData) {
this.data = data;
while (this.data.api && this.data.api.urlRoot.endsWith("/")) {
this.data.api.urlRoot = this.data.api.urlRoot.slice(0, -1)
}
}
auth0(): {clientId: string, clientSecret: string, domain: string} {
return {
clientId: this.data.auth0.clientId,
clientSecret: this.data.auth0.secret,
domain: this.data.auth0.domain,
}
}
session(): ConfigDataSession {
return this.data.session
}
apiUrl(path: string) {
return this.data.api.urlRoot + path;
}
jwtToken(username: string, expiry: number = 15): string {
return jwt.sign({
user: username,
exp: Math.floor((Date.now() / 1000) + expiry),
}, this.data.api.secretKey, {
header: {
kid: this.data.api.secretId,
}
})
}
}
export interface ConfigData {
api: ConfigDataAPI
auth0: ConfigDataAuth0
session: ConfigDataSession
redis: ConfigDataRedis
}
interface ConfigDataAPI {
urlRoot: string
secretId: string
secretKey: string
}
interface ConfigDataAuth0 {
secret: string
clientId: string
domain: string
}
interface ConfigDataSession {
secret: string
secure?: boolean
}
interface ConfigDataRedis {
host: string
port: number
}
const config = new Config(getConfig().serverRuntimeConfig);
export default config;