strapi / strapi-starter-next-corporate

Next.js starter for creating a corporate site with Strapi.
https://strapi-starter-next-corporate.vercel.app
MIT License
346 stars 95 forks source link

Deploy locally #4

Closed PaRoxUs closed 4 years ago

PaRoxUs commented 4 years ago

Although Heroku and Vercel provide smooth solutions, I'm experiencing the setup a bit overkill to test a starter app. The direction provided in this git might be more sustainable in the long run, but having a guide on how to run the app locally would be very much appreciated too!

KapilGahlot commented 4 years ago

I was able to run it locally by cloning the repo and doing below. I used postgres in the local setup.

Set up DB

  1. run postgres locally on port 5432

  2. create a new db named say strapidb in local postgres server

  3. cd in the cloned repo

  4. restore DB from the dump provided in the repo by executing following command in your terminal pg_restore -h localhost -p 5432 -d strapidb -U -W data.dump (enter password when prompted or if you have set auth for postgres don't use -W switch). Ignore warnings.

Set up backend

  1. cd cloned repo folder

  2. cd back

  3. yarn install

  4. copy .env.example to .env and set the environment variables

DATABASE_URL=postgres://user:pwd@localhost:5432/strapidb ADMIN_JWT_SECRET= FRONTEND_URL=http://localhost:3000 FRONTEND_PREVIEW_SECRET=

  1. edit back/config/database.js to comment out lines 7 to 24 which contain code to use sqllite in development mode. We are going to use postgres in development mode also so change line 27 to include development mode as well

      if (environment === 'production' || environment === 'development') {
  2. yarn develop

  3. open localhost:1337/admin in your browser and sign up for an admin account

  4. You should see Strapi admin console.

Set Up Front End

  1. cd cloned repo folder

  2. cd front

  3. yarn install

  4. copy .env.local.example to .env.local and set any value for PREVIEW_SECRET

  5. yarn dev or (yarn build and then yarn start)

  6. open localhost:3000 in your browser and you should see the app running.

juicecultus commented 4 years ago

@KapilGahlot

❯ yarn develop yarn run v1.22.4 $ strapi develop [2020-08-03T08:14:00.685Z] debug ⛔️ Server wasn't able to start properly. [2020-08-03T08:14:00.686Z] error Error: The server does not support SSL connections

KapilGahlot commented 4 years ago

The server does not support SSL connections

I did not face this issue but this could be related to line # 43 in back/config/database.js where ssl option is being set for the postgres database connection. Try below and then start the server by yarn develop.

Comment out line # 43 in back/config/database.js - // ssl: { rejectUnauthorized: false }

juicecultus commented 4 years ago

@KapilGahlot

weird behaviour, after commenting it out I get another error:

❯ yarn develop yarn run v1.22.4 $ strapi develop [2020-08-03T09:32:53.727Z] debug ⛔️ Server wasn't able to start properly. [2020-08-03T09:32:53.727Z] error error: role "user" does not exist

KapilGahlot commented 4 years ago

@KapilGahlot

weird behaviour, after commenting it out I get another error:

❯ yarn develop yarn run v1.22.4 $ strapi develop [2020-08-03T09:32:53.727Z] debug ⛔️ Server wasn't able to start properly. [2020-08-03T09:32:53.727Z] error error: role "user" does not exist

Assuming you were able to restore DB locally, the error you are getting is likely because of DB URL you are trying to connect to. Assuming you have not created a user for DB, please change DATABASE_URL in .env to DATABASE_URL=postgres://localhost:5432/strapidb and then restart server by yarn develop

In my earlier post I put user:pwd@ just as an example where actual user and password needed to be put in. If there is no user, you can ignore that and use what I mentioned here above.

juicecultus commented 4 years ago

Thanks, I should've picked up on that 👍

remidej commented 4 years ago

Hello there!

You're right, the experience to run this starter in development is not good enough.

We should use Postgres both in development and production. Though it requires more config than SQLite, it's worth it:

@KapilGahlot 's approach for this is great. I'll update the docs to recommend it.

Thanks for the early feedback!