Artemiy Davydov
03/16/2022, 11:16 AMthis.addDefaultFunctionEnv({
FRONTEND_URL: webStatic.url,
API_URL: api.url,
});
but const allowedOrigins = [process.env.FRONTEND_URL, "<http://localhost:3000>"];
shows [ undefined, '<http://localhost:3000>' ]
manitej
03/16/2022, 11:17 AMArtemiy Davydov
03/16/2022, 11:20 AMmanitej
03/16/2022, 11:21 AMArtemiy Davydov
03/16/2022, 11:22 AMimport * as sst from "@serverless-stack/resources";
import { TableFieldType } from "@serverless-stack/resources";
import path from "path";
export default class CoreStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const usersTable = new sst.Table(this, "UsersTable", {
fields: {
email: TableFieldType.STRING,
},
primaryIndex: { partitionKey: "email" },
});
const linksTable = new sst.Table(this, "LinksTable", {
fields: {
id: TableFieldType.STRING,
},
primaryIndex: { partitionKey: "id" },
});
const api = new sst.Api(this, "Api", {
cors: false,
defaultFunctionProps: {
// See /esbuild.js. This is necessary to support decorators
bundle: {
esbuildConfig: {
plugins: "esbuild-decorators-plugin.js",
},
},
environment: {
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID || "",
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET || "",
USERS_TABLE_NAME: usersTable.tableName,
LINKS_TABLE_NAME: linksTable.tableName,
},
permissions: [usersTable, linksTable],
},
routes: {
"GET /{id}": "src/functions/_id/get/handler.main",
"DELETE /links/{id}": "src/functions/links/_id/delete/handler.main",
"GET /links/{id}": "src/functions/links/_id/get/handler.main",
"PUT /links/{id}": "src/functions/links/_id/put/handler.main",
"POST /links/create": "src/functions/links/create/handler.main",
"GET /links/list": "src/functions/links/list/handler.main",
"GET /users/authRedirect":
"src/functions/users/authRedirect/handler.main",
"GET /users/me": "src/functions/users/me/handler.main",
},
});
const webStatic = new sst.ReactStaticSite(this, "WebStatic", {
path: path.resolve(__dirname, "../../frontend"),
environment: {
REACT_APP_API_URL: api.url,
},
cfDistribution: {
comment: "Distribution for React website",
},
});
this.addDefaultFunctionEnv({
FRONTEND_URL: webStatic.url,
API_URL: api.url,
});
this.addOutputs({
ApiEndpoint: api.url,
WebEndpoint: webStatic.url,
});
}
}
manitej
03/16/2022, 11:27 AMthis.addDefaultFunctionEnv({
FRONTEND_URL: webStatic.url,
API_URL: api.url,
});
seperately?Artemiy Davydov
03/16/2022, 11:30 AMAPI_URL
inside environment
objectmanitej
03/16/2022, 11:31 AMArtemiy Davydov
03/16/2022, 11:33 AMaddDefaultFunctionEnv
should add an environment variable only for lambda functions, therefore I cannot use it on the frontendArtemiy Davydov
03/16/2022, 11:34 AMmanitej
03/16/2022, 11:38 AMArtemiy Davydov
03/16/2022, 11:42 AMdocument.location
and after the second redirect from OAuth, I make a redirect to the frontendmanitej
03/16/2022, 11:46 AMArtemiy Davydov
03/16/2022, 11:50 AMFRONTEND_URL
and API_URL
are undefined. So my request to Google is uselessmanitej
03/16/2022, 11:52 AMREACT_APP_API_URL
Artemiy Davydov
03/16/2022, 11:54 AMaddDefaultFunctionEnv
?Artemiy Davydov
03/16/2022, 11:55 AMOnly functions created after acall will contain the new values.addDefaultFunctionEnv
Artemiy Davydov
03/16/2022, 11:56 AMmanitej
03/16/2022, 11:56 AMReactStaticSite
. ConstructArtemiy Davydov
03/16/2022, 11:57 AMFrank
addDefaultFunctionEnv
is meant to affect functions created after the call was made.Frank
// inside a stack
const fns = this.getAllFunctions();
fns.forEach(fn => {
fn.addEnvironment("FRONTEND_URL", webStatic.url);
fn.addEnvironment("API_URL", api.url);
});
Frank
Artemiy Davydov
03/17/2022, 10:11 AMexport const main = async (
event: APIGatewayProxyEventV2
): Promise<APIGatewayProxyResultV2> => {
return {
statusCode: 200,
body: JSON.stringify([process.env.WEB_URL, process.env.API_URL]),
};
};
And it returns
{
"message": "Internal Server Error"
}
without any output to the console or console.serverless-stack.com
Also, the hot reload doesn't seem to be workingArtemiy Davydov
03/17/2022, 11:29 AM