DEV Community

Cover image for Server-Side Rendered Real-time Web App with Next.js, AWS Amplify & GraphQL

Server-Side Rendered Real-time Web App with Next.js, AWS Amplify & GraphQL

Rakan Nimer on July 25, 2019

In this blog post we will go through building a server-rendered realtime collaborative todo list app with Next.js and AWS Amplify. You can check o...
Collapse
 
2manoj1 profile image
Manoj Mukherjee

How to deploy Nextjs frontend (SSR) in amplify console?

Collapse
 
rakannimer profile image
Rakan Nimer

You will need to do :

next build && next export

This will generate a static version of your app in the out directory

Then point Amplify Console to the out directory by setting artifacts -> baseDirectory in your amplify config : docs.aws.amazon.com/amplify/latest...

Collapse
 
gauravhanda25 profile image
Gaurav Handa

I did same but still access denied error page on my production branch url - master.d1pgdow2brm58j.amplifyapp.com/

Thread Thread
 
upupkenchoong profile image
Ken Choong

Ya I also have access denied when done generate the page. When start SSR build, it go to Access Denied.

I have attached AdminstratorAccess to the service role, but it still the same.

Do you have any fix on this??

Collapse
 
2manoj1 profile image
Manoj Mukherjee

Thank you. Can I deploy Nextjs API with this?

Thread Thread
 
rakannimer profile image
Rakan Nimer

No, unfortunately you can't deploy the API directory like this, this is only for your static assets and for the api calls you will need a node server. You can use zeit's now to easily deploy the API, alternatively you can use any provider that supports node apps deployment and then running npm run build && npm run start.

Thread Thread
 
devth profile image
Trevor Hartman

Why is the title of this article "Server-Side Rendered Real-time Web App with Next.js, AWS Amplify" if Amplify doesn't support SSR? 🤔

Thread Thread
 
rakannimer profile image
Rakan Nimer • Edited

Amplify Console doesn't support SSR but you can use the Amplify API to populate the data for your page on the server side

Collapse
 
scorpian555 profile image
Ian

ts -v = 3.6.2
reactjs -v = 16.9.2

Line 64 in my file, on the add() method definition (at add.payload.name), was getting a "cannot find name 'currentTodo'" error.

Changed name: currentTodo => name: state.currentTodo
Then, deleted state.currentTodo entirely from

add method

works ok now... I'm brand new to typescript & React Hooks so not sure if those changes will bite me later but so far good project to learn these...

Collapse
 
rakannimer profile image
Rakan Nimer

Thanks for reporting that, I updated the post to fix it 👍

Collapse
 
johhansantana profile image
Johhan Santana • Edited

I love this. I’ve used prisma.io for graphql a lot before but I want to try amplify appsync. The only thing I think it’s missing is how to handle what the user can or can’t do when using the queries or mutations. Do you know any good read for this?

Collapse
 
rakannimer profile image
Rakan Nimer

That's true it doesn't go into how to handle auth and user permissions. I would recommend checking out the chatt app codebase here It's complete and written very clearly and make sure to read the overview post here.

Collapse
 
unic0arn profile image
Fredrik Hallberg

Awesome tutorial! I don't know why but for the subscriptions to work I had to configure PubSub with
PubSub.configure(config);

I also think the subscribe function in the observable type should return an object with an unsubscribe function.

Collapse
 
jamescarr profile image
James Carr

Thanks for this... one thing that has gotten immensely confusing as I walk through this is where src/API comes from in import { GetTodoListQuery } from "../src/API"; .

Locally, that does not exist.

Collapse
 
markau_48 profile image
Mark

amplify configure codegen

Collapse
 
moflo profile image
moflo

Awesome, thanks! Noticed your reducer code omits the set-current method, although this is included in the repo. Really nice writeup, makes me want to learn more about Amplify !

Collapse
 
rakannimer profile image
Rakan Nimer

Thanks for catching that, I updated the post 👍

Collapse
 
gcid12 profile image
Gerardo Cid

I was literally pulling my hair off yesterday to understand how getInitialProps works with AppSync, thank you very much for this step by step.

Collapse
 
rakannimer profile image
Rakan Nimer

Same happened to me, that's why I decided to write it :D
Happy it helps

Collapse
 
simmbiote profile image
JBS

To be clear, you can't actually host full Next.js SSR sites on AWS Amplify - only static exported versions.

Collapse
 
hamzaanis profile image
Hamza Anis

Is there any way to deploy it on AWS. if not then what are the good alternatives.

Collapse
 
jonczeck profile image
Jon Czeck

That answer is out of date. You can now. aws.amazon.com/blogs/mobile/host-a...

Thread Thread
 
hamzaanis profile image
Hamza Anis

Thanks for the update. :)