Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aws - Amplify - SEO friendly approach #4972

Closed
yvescoinpass opened this issue Feb 24, 2020 · 15 comments
Closed

Aws - Amplify - SEO friendly approach #4972

yvescoinpass opened this issue Feb 24, 2020 · 15 comments
Assignees

Comments

@yvescoinpass
Copy link

Which Category is your question related to?*
API

Amplify CLI Version
4.13.4

What AWS Services are you utilizing?
AWS Appsync

Provide additional details e.g. code snippets

I am creating a blogging application using using Aws Amplify. I am concern how will the SEO be handle on this type of application because the result will be a SPA. I read so many articles that SPA is not good in SEO. That is why I am asking the best approach to handle this application as SEO friendly.

I already tried Next JS. I was not a success and I posted an issue on Next JS repo vercel/next.js#10522

The next thing I am currently trying now is Redux SSR. I am confused about using this tool because I needed a node server to do an SSR. But I am using AWS Amplify which is a serverless type application. Is there a tutorial or resources how we can do it?

The last resort I have in mind is CSR approach which is not good in SEO as I have read.

If you have a better idea please let me know.

@kaustavghosh06 kaustavghosh06 transferred this issue from aws-amplify/amplify-cli Feb 24, 2020
@alexofob
Copy link

Your best bet may be Nextjs. I am doing Nextjs with Amplify. I am using aws appsync and apollographql to enable me fetch data from backend built with Amplify.

@yvescoinpass
Copy link
Author

@alexofob I have issue using nextjs for SSR. vercel/next.js#10522

@blairtaylor
Copy link

We also have the same issue / concern. Would appreciate input on the subject.

@ericclemmons ericclemmons added this to the Support SSR (Auth + API) milestone Mar 17, 2020
@stale
Copy link

stale bot commented Apr 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@MontoyaAndres
Copy link

MontoyaAndres commented Apr 26, 2020

AppSync works for me fine for SEO, in my case I use the new method getServerSideProps like this:

export async function getServerSideProps({ params }) {
  const { data } = (await API.graphql(
    graphqlOperation(GetPublicationByID, { id: params.project })
  )) as GraphQLResult<GetPublicationQuery>;

  return {
    props: {
      publication: data.getPublication,
    },
  };
}

And it returns the right data :)

@MontoyaAndres
Copy link

MontoyaAndres commented May 2, 2020

New update about the previous comment I did, if you're using Multi-Auth, in my case I'm using AWS_IAM and AMAZON_COGNITO_USER_POOLS, you need to configure the "auth mode" on each query:

import { GRAPHQL_AUTH_MODE } from "@aws-amplify/api";

// client side queries
export const AUTH_MODE =
  process.env.NODE_ENV === "production" ? GRAPHQL_AUTH_MODE.AWS_IAM : undefined;

// server side queries
export const AUTH_MODE_SSR = GRAPHQL_AUTH_MODE.AWS_IAM;

And the query would be something like this:

const { data } = (await API.graphql({
    query: GetPublicationByID,
    variables: {
      id: params.project,
    },
    authMode: // here AUTH_MODE or AUTH_MODE_SSR depending the use case,
  })) as GraphQLResult<GetPublicationQuery>;

@ericclemmons
Copy link
Contributor

@MontoyaAndres Great find here! Why does the authMode depend on process.env.NODE_ENV === "production" in your case? In development how are the queries working successfully?

@MontoyaAndres
Copy link

MontoyaAndres commented May 5, 2020

@ericclemmons, If I'm doing a query on development, the API.graphql method does not ask me for the "auth mode" field, but if I deploy the project (in my case is vercel) amplify throws me an error like "The api is not configured" something like that I remember... So, the solution was adding the "auth mode" just in production.

In the case of SSR, the query always asks me for the Auth mode, if I don't use it, amplify throws me the same error, "The api is not configured"

@ericclemmons
Copy link
Contributor

@MontoyaAndres Thanks for the additional info. I'll use this in my testing.

@yvescoinpass
Copy link
Author

yvescoinpass commented May 6, 2020

@MontoyaAndres Did you mean the nextjs function getServerSideProps()? That's interesting. How did you build and deploy on Aws Amplify?

@MontoyaAndres
Copy link

MontoyaAndres commented May 6, 2020

@yvescoinpass the application is not deployed on aws, it's on vercel, you just need to remove the "aws-exports.js" file from the .gitignore, and the application will work :)

@stale
Copy link

stale bot commented Jun 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jul 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jul 12, 2020

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Jul 12, 2020
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants