Karolis Stulgys
04/01/2022, 9:37 PMnpx sst start
everything works fine with the endpoint.
Then I npx sst deploy --stage prod
and I get an error on the frontend:Devin
04/01/2022, 9:40 PMKarolis Stulgys
04/01/2022, 9:44 PMDevin
04/01/2022, 9:44 PMKarolis Stulgys
04/01/2022, 9:45 PMDevin
04/01/2022, 9:46 PM// Create the HTTP API
const api = new sst.Api(this, "Api", {
routes: {
"GET /notes": "src/list.main",
"GET /notes/{id}": "src/get.main",
"PUT /notes/{id}": "src/update.main",
},
});
May I see what you have that's like that?Karolis Stulgys
04/01/2022, 9:47 PMimport { LayerVersion } from "aws-cdk-lib/aws-lambda";
import * as sst from "@serverless-stack/resources";
const layerArn =
"arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:22";
export default class MyStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const layer = LayerVersion.fromLayerVersionArn(this, "Layer", layerArn);
// Create a HTTP API
const api = new sst.Api(this, "Api", {
routes: {
"POST /": {
function: {
handler: "src/lambda.handler",
// Increase the timeout for generating screenshots
timeout: 15,
// Load Chrome in a Layer
layers: [layer],
// Exclude bundling it in the Lambda function
bundle: { externalModules: ["chrome-aws-lambda"] },
},
},
},
});
// Show the endpoint in the output
this.addOutputs({
ApiEndpoint: api.url,
});
}
}
Karolis Stulgys
04/01/2022, 9:49 PMDevin
04/01/2022, 9:51 PMKarolis Stulgys
04/01/2022, 9:51 PMKarolis Stulgys
04/01/2022, 9:52 PMDevin
04/01/2022, 9:56 PM// allow cors
new Api(this, "Api", {
cors: {
allowMethods: [CorsHttpMethod.GET],
},
or auth type
"POST /cool-route": {
authorizationType: sst.ApiAuthorizationType.NONE,
function: "src/coolFunction.main"
},
Perhaps you’ll be able to find what you need here as well
https://docs.serverless-stack.com/constructs/Api#configuring-corsKarolis Stulgys
04/01/2022, 10:01 PMKarolis Stulgys
04/01/2022, 10:06 PMconst api = new sst.Api(this, "Api", {
cors: {
allowMethods: [<http://CorsHttpMethod.POST|CorsHttpMethod.POST>],
allowOrigins: ["<http://localhost:3000>"],
},
Karolis Stulgys
04/01/2022, 10:07 PMDevin
04/01/2022, 10:09 PMauthorizationType: sst.ApiAuthorizationType.NONE,
from
import * as sst from "@serverless-stack/resources";
Devin
04/01/2022, 10:09 PMKarolis Stulgys
04/01/2022, 10:17 PMfrom origin '<http://localhost:3000>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Karolis Stulgys
04/01/2022, 10:19 PMfrom origin '<https://4d76-78-58-239-79.ngrok.io>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Karolis Stulgys
04/01/2022, 10:42 PMcors: {
allowHeaders: ["*"],
allowOrigins: ["*"],
allowMethods: [CorsHttpMethod.ANY],
},
Karolis Stulgys
04/01/2022, 10:42 PMDevin
04/01/2022, 10:59 PMKarolis Stulgys
04/01/2022, 11:01 PMKristian Lake
04/02/2022, 12:11 PMallowOrigins: [<http://localhost:3000>],
Kristian Lake
04/02/2022, 12:11 PMKristian Lake
04/02/2022, 12:13 PMKarolis Stulgys
04/02/2022, 3:08 PMstacks/index.js
app.setDefaultFunctionProps({
runtime: "nodejs14.x", // change to "nodejs12.x"
});