Alt cafe24

What is cafe24?

I tried to host test web server by hosting. And the hosting web site 'Cafe24' is beloved in Korea for shopping mall or online market companies. I made a summary for making a web server at cafe24.

Alt cafe24manage

My first app at cafe24

Alt Text

  • Click '나의 서비스 관리' at main page and click '앱 생성/관리'.
  • If you haven't create your app then make your app typing your app name and click 'node.js 앱 만들기'.
  • You can see '도메인(domain)' 'your-app-name.cafe24app.com'(or your domain name), '저장소(git page)' 'git your-id@your-app-name.cafe24app.com:your-id_yourappname' and we use these later.

Write nodejs server

  • Type mkdir nodeservertest && cd nodeservertest on your terminal.
  • Write web.js file and put below :
const express = require('express')
const mysql = require('mysql')

const app = express();

const con = mysql.createConnection({
    host: 'nodejs-***.cafe24.com',
    user: 'your-id',
    password: 'your-password',
    database: 'databasename'
});

app.get('/', (err, result) => {
    con.query('SELECT * FROM api', (err, res) => {
       result.json(res);
    });    
});

const port = 8001;

app.listen(port, console.log(`Server is connected`));
  • Type npm init -y on your terminal.
  • Type npm install express mysql.

Edit information mysql connection

  • Open web.js file and you can see MySQL connection configuration.
  • Put information at cafe24 '앱 생성/관리'
const con = mysql.createConnection({
    host: 'nodejs-***.cafe24.com',
    user: 'your-id',
    password: 'your-password',
    database: 'your-id'
});
  • You can change password at 'DB 비밀번호 변경' on your cafe24 management pannel '나의 서비스 관리'.
  • Check your host at 'MySQL 웹어드민'

Publick Key

  • If you haven't create your SSH publick key then please to make at: https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key
  • Click 'Publick Key 관리' on your '나의 서비스 관리' page(On left nav) at cafe24.
  • Put any key name at 'Public Key 이름' and Publick key at 'Public Key 입력'.

Set up your git config on your linux for cafe24 account

  • Go back to * Click '나의 서비스 관리' at main page and click '앱 생성/관리' at your cafe24.
  • You can see '도메인(domain)' 'your-app-name.cafe24app.com'(or your domain name), '저장소(git page)' 'git your-id@your-app-name.cafe24app.com:your-id_yourappname'.
  • Set configuration of git by typing git config --global user.name 'your-id'_'your-app-name'.
  • Type git config --global user.email 'your-id'@'your-app-name'.cafe24app.com'
  • You can check your config of git by typing git config --global --list.

Upload your files on git

  • Type git init on your 'nodeservertest' directory on your terminal.
  • Add a link by typing git remote add 'your-app-name' your-id@your-app-name.cafe24app.com:your-id_yourappname
  • Type git add .(Means add all your files.)
  • Type git commit -m 'what you want to write' (You can write info about what you uploaded).
  • Type git push -u master(Upload files on git page). Uploading scripts is finished.

Connect db to your node.js server.

  • Click '서비스 사용현황'(Hosting status) on your '나의 서비스 관리' page(On left nav).
  • Add external IP address at 'MySQL 외부 IP 접근설정'.
  • You can check by searching 'IP address' by googling.
  • Click 'MySQL 웹어드민'(MySQL webadmin) on your '나의 서비스 관리' page(On left nav).
  • Check URL nodejs-***.cafe24.com/WebMysql'. You need 'nodejs-***.cafe24.com later.
  • If you haven't install mysql then type sudo apt-get install mysql.
  • Type sudo service mysql start to run mysql server.
  • You can check your mysql server status by typing sudo service mysql status.
  • Type mysql -h 'nodejs-***.cafe24.com' -u 'your-id' -p.
  • Put your password and enter.
  • Type at mysql session,
USE your-id

CREATE TABLE api
(id int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT, 
name varchar(50) NOT NULL, 
email varchar(255) NOT NULL);

INSERT INTO api VALUES
(1, "test", "test@test.com");

Now let's check your nodejs API server entering address on your browser 'your-app-name.cafe24app.com'.

Logo

华为、百度、京东云现已入驻,来创建你的专属开发者社区吧!

更多推荐