From 96923adae26d77be647b8d5c66f900ca627f9f14 Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Wed, 19 Feb 2020 15:17:40 +0530 Subject: [PATCH] fixes --- next.config.js | 6 +++++- pages/api/flow-to-typescript.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/next.config.js b/next.config.js index a74966c..570747d 100644 --- a/next.config.js +++ b/next.config.js @@ -73,7 +73,11 @@ const config = { return config; }, - target: "serverless" + target: "serverless", + + serverRuntimeConfig: { + PROJECT_ROOT: __dirname + } }; module.exports = withBundleAnalyzer(withCSS(config)); diff --git a/pages/api/flow-to-typescript.ts b/pages/api/flow-to-typescript.ts index 50fe5a6..721f294 100644 --- a/pages/api/flow-to-typescript.ts +++ b/pages/api/flow-to-typescript.ts @@ -2,9 +2,20 @@ import { NextApiRequest, NextApiResponse } from "next"; import convert from "@khanacademy/flow-to-ts"; import * as ts from "typescript"; import * as fs from "fs"; +import * as path from "path"; +import getConfig from "next/config"; +const { serverRuntimeConfig } = getConfig(); const libSource = fs - .readFileSync("./node_modules/typescript/lib/lib.d.ts") + .readFileSync( + path.join( + serverRuntimeConfig.PROJECT_ROOT, + "node_modules", + "typescript", + "lib", + "lib.d.ts" + ) + ) .toString(); export default (req: NextApiRequest, res: NextApiResponse) => {