헤로쿠에 올려보자.
헤로쿠는 진짜 정말 쉽고 좋다. node같은경우 몇가지만 세팅해두면 알아서 다 해준다. 내가 올린프로젝트는 react로 만든 아주 심플한 프로젝트였고 webpack
을 사용하는 프로젝트였다. 다른 모듈번들러를 사용해도 크게 다를건 없으니 알아서 맞춰서 잘하면 된다.
참고
- https://devcenter.heroku.com/articles/deploying-nodejs
- https://devcenter.heroku.com/articles/gitignore
헤로쿠에 로그인한뒤 Create New App 를 눌러 새로만든다.
pacakge.json
에 아래 코드를 추가한다.
"scripts": {
"postinstall": "webpack -p",
"start": "node server.js"
},
npm run postinstall
로 node로 서버를 열었을때 사용할 bundle.js
파일을 만들고, npm run start
커맨드로 node server.js
커맨드를 실행한다. (기존에 npm start
가 있었다면, npm dev
정도로 바꿔주자.)
server.js
를 만든다.
const express = require('express');
const path = require('path');
const post = process.env.POST || 8080;
const app = express();
app.use(express.static(__dirname));
app.get('*', (req,res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
})
app.listen(port);
console.log("Server started");
이제 헤로쿠와 연결한다.
헤로쿠는 당연히 설치되어 있어야한다. 설치안했다면 brew install heroku
heroku login # email, password 입력
cd my-project/
git init
git add .
git commit -m "first commit"
heroku git:remote -a desolate-plateau-*****
git push heroku master
왠만하면 에러가 나지 않지만 만약 에러가 나면 heroku logs
에서 확인해라.
(오타아니면 오류안남...미친오타때매 1시간날렸네 port를 post로 쓰지말자 제발.)