Skip to content

Instantly share code, notes, and snippets.

@maisnamraju
Last active April 18, 2020 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maisnamraju/3736805fdb3394e36caf3bfaecd3a284 to your computer and use it in GitHub Desktop.
Save maisnamraju/3736805fdb3394e36caf3bfaecd3a284 to your computer and use it in GitHub Desktop.
Zeit now routing issue with CORS error
import { NowRequest, NowResponse } from '@now/node';
import { query as q } from 'faunadb';
import { v4 as uuidv4 } from 'uuid';
export default async (req: NowRequest, res: NowResponse) => {
const { body } = req;
console.log(body);
// the body field returns as undefined
}
import { NowRequest, NowResponse } from '@now/node';
import { v4 as uuidv4 } from 'uuid';
import { query as q } from 'faunadb';
import client from '../_lib/faunadb';
export default async (req: NowRequest, res: NowResponse) => {
const { body } = req;
if (!client) {
return [];
}
try {
// need to get this query to get [objects] instead of [strings]
let invites = (await client.query(
q.Map(
q.Paginate(q.Match(q.Index("All_Invites"))),
q.Lambda("nextRef", q.Get(q.Var("nextRef")))
))).data.map(i => i.data);
if (invites) {
res.status(200).json({
invites
});
} else {
res.status(404).json({
success: false,
message: `couldn't retreive invites`
});
}
} catch (error) {
console.log(error);
res.status(500).json({
success: false,
message: error.message
})
}
}
{
"routes": [
{
"src": "/.*",
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*"
},
"continue": true
},
{
"src": "/auth/invite",
"methods": [
"POST"
],
"dest": "/api/auth/invite-user.ts"
},
{
"src": "/auth/invites",
"methods": [
"GET"
],
"dest": "/api/auth/invites.ts"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment