Giter Site home page Giter Site logo

jimmylee / next-postgres-sequelize Goto Github PK

View Code? Open in Web Editor NEW
180.0 8.0 39.0 280 KB

[OUTDATED] React 16.8.4 + NextJS 8.0.3 + Emotion + Sequelize 5/Postgres + Passport Local Auth + Google App Engine or Heroku Deployment

Home Page: https://next-postgres.herokuapp.com/

License: MIT License

JavaScript 100.00%
nextjs postgres passport sequelize react heroku redux emotion google-app-engine

next-postgres-sequelize's Introduction

DEPRECATION NOTICE

This template is no longer up to date. For an updated template, either as a team or individually, we encourage you to explore our latest template produced by INTDEV. Thank you for your interest in our work!

next-postgres

January 4th, 2022I recommend you use www-react-postgres instead because it does not have an express server or a need for babel, therefore the template has less dependencies. That means there will be less attention cost required.

An example app with...

  • Posts
  • Comments
  • Authentication

With some nice qualities...

  • Full stack JavaScript
  • Server side rendering

And you can deploy it to...

Feel free to use without attribution!

Production Examples:

Preview:

Stack

Why is this useful? Why should I care?

  • Bad UX/UI so you are forced to make it your own!
  • Some "production ready" are concepts baked in for you.
  • You'll get server side rendering for free.
  • You can move a little faster at a competition or hackathon.

Setup: Prerequisites

I use Homebrew to manage dependencies.

  • Install Postgres: brew install postgres.
  • Install Node 10.7.0+: brew install node. (Or update your node)

Setup: Quick newbies guide to Postgres

  • On OSX, to run Postgres in a tab on the default port.
postgres -D /usr/local/var/postgres -p 5432
  • Postgres config is stored in ./config.js.
  • Local database: sampledb.
  • Username: test.
  • Password: test.
  • Please come up with something better in production.

First time Postgres instructions.

# Enter Postgres console
psql postgres

# Create a new user for yourself
CREATE ROLE yourname WITH LOGIN PASSWORD 'yourname';

# Allow yourself to create databases
ALTER ROLE yourname CREATEDB;

# Exit Postgres console
\q

# Log in as your new user.
psql postgres -U yourname

# Create a database named: sampledb.
# If you change this, update config.js
CREATE DATABASE sampledb;

# Give your self privileges
GRANT ALL PRIVILEGES ON DATABASE sampledb TO yourname;

# List all of your databases
\list

# Connect to your newly created DB as a test
\connect sampledb

# Exit Postgres console
\q

Newbie tip: I use an app called TablePlus for postgres.

Setup: Run locally

In the root directory run these commands:

npm install
npm install -g babel-cli
npm install -g sequelize-cli
sequelize db:migrate
npm run dev
  • Visit localhost:8000 in a browser to start development locally.
  • You will need postgres running.

Deploy Heroku

To deploy with Heroku, please follow the instructions here.

Deploy Google App Engine

Please set up Google App Engine and download the Google Cloud SDK so you can use gcloud from the command line.

You will need to add an app.yaml. It will look something like this:

runtime: nodejs
env: flex

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

env_variables:
  NODE_ENV: production
  PRODUCTION_USERNAME: your-database-username
  PRODUCTION_PASSWORD: your-database-user-password
  PRODUCTION_DATABASE: your-database-name
  PRODUCTION_HOST: your-database-host
  PRODUCTION_PORT: your-database-port
  PRODUCTION_SECRET: your-secret

Be sure to read the documentation

Make sure you add app.yaml to the .gitignore. You don't want to commit this file into your Github repository.

Then run npm run deploy. This configuration will cost you ~$40 a month.

What happened to Zeit's Now service?

  • It is a great service.
  • Now 2.0 is about serverless everything
  • This example doesn't work with Now 2.0

Questions?

Feel free to slang any feels to @wwwjim.

next-postgres-sequelize's People

Contributors

huyhong avatar jimmylee avatar pruhstal avatar whyrusleeping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-postgres-sequelize's Issues

Using with decoupled API?

Hi there, wonderful library!

Apologies if this isn't a great place for this question, however I've pored over articles/SO/tutorials for awhile now and thought I'd give it a shot here!

I was wondering if you had any suggestions on implementing what you've created here with a decoupled API. In my repo I've got an 'api' folder which contains my Rails API for handling user authentication, but I know this library uses Express/Passport for user authentication. On my frontend I'm using Next.js and modeled my login after this repo.

Thank you!

Change paths for textarea, moved under higher-order

In components directory, CommentForm.js, CommentPreview.js, PostForm.js
and in pages directory, pages/post.js
all had paths expecting Textarea to be under components, but it has been moved to the folder higher-order.

How to connect hosted postgres database secrets?

Amazing repo, thank you for open sourcing. I am trying to connect the project with ElephantSQL's hosted postgres database, but I am unsure of what fields correspond with the fields you included in next-postgres' readme.

Here's a screenshot of a test instance of ElephantSQL:

Screen Shot 2019-03-19 at 10 53 05 AM

In the example you provided, are all the fields required? So far, I have guessed the following pairings, but hasn't doesn't worked.

now secrets add production-username   [User & default database]
now secrets add production-password   [Password]
now secrets add production-database   [Default database or server?]
now secrets add production-host       [Server or URL?]
now secrets add production-port       [Default to 5432?]
now secrets add production-secret     [API Key?]

Thanks for the help!

Building Production Version with Now?

Have you tried running the production build?

I get the following error: error [email protected]: The engine "node" is incompatible with this module. Expected version "10.6.0".

Works if you take out the engine key in package.json. Is that expected?

Full error:

next-postgres-now$ now --public
> Deploying ~/Downloads/next-postgres-now under idkjs
> Synced 1 file (3.37KB) [985ms]
> WARN! Requested node version 10.6.0 is not available
> Using Node.js 8.11.3 (default)
> https://next-postgres-kkgivgnkry.now.sh [in clipboard] (bru1) [5s]
> Building…
> ▲ yarn
> yarn install v1.9.4
> info No lockfile found.
> [1/5] Validating package.json...
> error next-postgres@1.0.0: The engine "node" is incompatible with this module. Expected version "10.6.0".
> Logs from deployments of your account are rate limited. The reason is "writes from reason-docker-server-master-ydunocaape.now.sh". Please upgrade your plan.
> info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
> Error! Build failed

Great Project. Thanks for sharing.

Handling modal state

I apologize if this is a question that is outside of the scope of this repo, but I'm just unable to find a solution and I'm hoping you can provide a little guidance!

I'm relatively new to the React world (coming from Rails). I've used your next-postgres repo as a guide and altered what I need to fit my app. I'm working on creating a signup modal using Material-UI, however when I hit the Submit button, I get an error:
Unhandled Rejection (TypeError): Cannot read property 'toLowerCase' of undefined

This error is in http.js (line 166), where none of the information is being passed through to the signup method.

I have state set in the parent component (just to check whether the modal is open), and I have state set in the modal component to capture form values. When I console state in the modal component however, it only returns the parent state instead of modal state, which would be the issue back over in http.js.

Do you have any tips or guidance as to how to handle this?
Feel free to remove this question if this isn't a good place for a question like this.

Suggestion on how to fetch data on a per page basis?

Hi @jimmylee,

I've been using this repo for about 3 months (since you first released it), and I've been able to fly pretty fast on a side project. So thank you so much for the nice starter kit.

One thing I noticed is that most of the data for all of the pages (comments, posts, etc.) comes from getInitialStateData from within https://github.com/jimmylee/next-postgres/blob/master/higher-order/withData.js#L9. While I can see why the reasoning behind it, it's not entirely optimal on sites that depend on a lot of data.

I'd like to get your thoughts on patterns to fetch data on a per-page basis that would be SEO friendly.

One solution I have for now is on a (logged in) page, say privacy.js: is within componentWillMount doing the fetch and then setting the state for the component based upon what comes back.

E.g.

  componentWillMount() {
    return this.props.dispatch(Actions.requestGetUserPrivacySettings({
      userId: this.props.viewer.id
    })).then((settings) => {
      this.setState(settings);
    });
  }

This works, but like I mentioned, I'd like to have something a bit more SEO friendly. I thought about maybe doing it in one of the controllers (within the route) kinda like this:

https://github.com/jimmylee/next-postgres/blob/master/index.js#L39

Where I'd just fetch the data and somehow pass it through to the component, but I'm stuck on how to do that.

Any ideas?

Not working locally

Hi Jimmy,

First off -- awesome repo. Been looking for something like this for a couple of days after finally having settled on Next.js. This is like the holy grail of examples.

Which is why I'm trying to get it to work properly, to no avail.

I followed the instructions, ran the migrations (confirmed that the tables were created), and then get the standard next.js output:

 DONE  Compiled successfully in 1701ms                                                                                                                                                          

Running on localhost:8000

From there, I head over to http://localhost:8000 and get the following:

screen shot 2017-08-04 at 4 52 44 pm

Not even sure where to debug this thing since there's not really any output/logging happening when I hit the URL.

Any idea on where to look?

Cheers

Clean install has issues with babel-cli

When starting the app with yarn dev I kept receiving the message

Error: Plugin 0 specified in "[...]/node_modules/next/babel.js" provided an invalid property of "default"

After removing babel-cli and instead installing @babel/cli local to the project everything started working as expected.

Sequelize 5 Warning

(node:19304) [SEQUELIZE0003]
DeprecationWarning: String based operators are deprecated. 
Please use Symbol based operators for better security, 
read more at 

http://docs.sequelizejs.com/manual/querying.html#operators

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.