Consolidate .env files. More work on dev containers.
This commit is contained in:
parent
2a959f354c
commit
3773d659cc
17 changed files with 137 additions and 106 deletions
|
@ -9,6 +9,7 @@ import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments";
|
|||
import { ApiUserInfo } from "../data/ApiUserInfo";
|
||||
import { ApiUserInfoData } from "../data/entities/ApiUserInfo";
|
||||
import { ok } from "./responses";
|
||||
import { env } from "../env";
|
||||
|
||||
interface IPassportApiUser {
|
||||
apiKey: string;
|
||||
|
@ -54,22 +55,6 @@ function simpleDiscordAPIRequest(bearerToken, path): Promise<any> {
|
|||
export function initAuth(app: express.Express) {
|
||||
app.use(passport.initialize());
|
||||
|
||||
if (!process.env.CLIENT_ID) {
|
||||
throw new Error("Auth: CLIENT ID missing");
|
||||
}
|
||||
|
||||
if (!process.env.CLIENT_SECRET) {
|
||||
throw new Error("Auth: CLIENT SECRET missing");
|
||||
}
|
||||
|
||||
if (!process.env.OAUTH_CALLBACK_URL) {
|
||||
throw new Error("Auth: OAUTH CALLBACK URL missing");
|
||||
}
|
||||
|
||||
if (!process.env.DASHBOARD_URL) {
|
||||
throw new Error("DASHBOARD_URL missing!");
|
||||
}
|
||||
|
||||
passport.serializeUser((user, done) => done(null, user));
|
||||
passport.deserializeUser((user, done) => done(null, user));
|
||||
|
||||
|
@ -101,9 +86,9 @@ export function initAuth(app: express.Express) {
|
|||
{
|
||||
authorizationURL: "https://discord.com/api/oauth2/authorize",
|
||||
tokenURL: "https://discord.com/api/oauth2/token",
|
||||
clientID: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
callbackURL: process.env.OAUTH_CALLBACK_URL,
|
||||
clientID: env.CLIENT_ID,
|
||||
clientSecret: env.CLIENT_SECRET,
|
||||
callbackURL: env.OAUTH_CALLBACK_URL,
|
||||
scope: ["identify"],
|
||||
},
|
||||
async (accessToken, refreshToken, profile, cb) => {
|
||||
|
@ -132,9 +117,9 @@ export function initAuth(app: express.Express) {
|
|||
passport.authenticate("oauth2", { failureRedirect: "/", session: false }),
|
||||
(req: Request, res: Response) => {
|
||||
if (req.user && req.user.apiKey) {
|
||||
res.redirect(`${process.env.DASHBOARD_URL}/login-callback/?apiKey=${req.user.apiKey}`);
|
||||
res.redirect(`https://${env.DASHBOARD_DOMAIN}/login-callback/?apiKey=${req.user.apiKey}`);
|
||||
} else {
|
||||
res.redirect(`${process.env.DASHBOARD_URL}/login-callback/?error=noAccess`);
|
||||
res.redirect(`https://${env.DASHBOARD_DOMAIN}/login-callback/?error=noAccess`);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { connect } from "../data/db";
|
||||
import { setIsAPI } from "../globals";
|
||||
import "./loadEnv";
|
||||
import { apiEnv } from "./loadApiEnv";
|
||||
|
||||
if (!process.env.KEY) {
|
||||
if (!apiEnv.KEY) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.error("Project root .env with KEY is required!");
|
||||
process.exit(1);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
import path from "path";
|
||||
|
||||
require("dotenv").config({ path: path.resolve(process.cwd(), "../.env") });
|
||||
require("dotenv").config({ path: path.resolve(process.cwd(), "api.env") });
|
|
@ -8,12 +8,13 @@ import { initGuildsAPI } from "./guilds/index";
|
|||
import { clientError, error, notFound } from "./responses";
|
||||
import { startBackgroundTasks } from "./tasks";
|
||||
import multer from "multer";
|
||||
import { env } from "../env";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin: process.env.DASHBOARD_URL,
|
||||
origin: `https://${env.DASHBOARD_DOMAIN}`,
|
||||
}),
|
||||
);
|
||||
app.use(
|
||||
|
@ -48,7 +49,7 @@ app.use((req, res, next) => {
|
|||
return notFound(res);
|
||||
});
|
||||
|
||||
const port = (process.env.PORT && parseInt(process.env.PORT, 10)) || 3000;
|
||||
const port = env.API_PORT;
|
||||
app.listen(port, "0.0.0.0", () => console.log(`API server listening on port ${port}`)); // tslint:disable-line
|
||||
|
||||
startBackgroundTasks();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue