먼저 해당 글은 Keystonejs로 deploy를 한다는 베이스 하에 진행 됩니다.


Nextjs deploy 방법은 


https://nextjs.org/docs/#production-deployment 참고하세요.


Keystonejs deploy 방법은 .env 파일에 NODE_ENV=production 를 추가하고


keystone.js 파일에서


// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require("dotenv").config();

const next = require("next");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });

// Require keystone
var keystone = require("keystone");

// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.

keystone.init({
    name: "NextExample",
    brand: "NextExample",
    favicon: "public/favicon.ico",
    "auto update": true,
    session: true,
    auth: true,
    "user model": "User"
});

// Load your project's Models
keystone.import("models");

// Start Next app
app.prepare().then(() => {
    // Load your project's Routes
    keystone.set("routes", require("./routes")(app));

    // Configure the navigation bar in Keystone's Admin UI
    keystone.set("nav", {
        posts: ["posts", "post-categories"],
        users: "users"
    });

    keystone.start();
});


const dev = process.env.NODE_ENV !== "production";



const dev = process.env.NODE_ENV === "production";


로 바꾸고 터미널에서

node keystone 으로 실행하면 끝....


헤맸던 이유

 - Keystone 과 Next 둘 중 베이스를 정한 뒤, 어떤걸 build 시키고 어떤걸 deploy 시키는지에 관해 개념이 모호하였음.

 - .env 에서 NODE_ENV=production 을 작성만 하면 되는지 알고 작성 뒤 실행시키니 


터미널에


throw new Error("Could not find a valid build in the '".concat(this.distDir, "' directory! Try building your app with 'next build' before starting the server."));

        ^


Error: Could not find a valid build in the '/home/pc/Documents/Projects/nextexample/.next' directory! Try building your app with 'next build' before starting the server.


가 나와서 나도 모르게 당연히, next build 를 먼저 하고 해야한다고 생각해버림.....


오늘 또 한삽 거하게 펐다... 

+ Recent posts