소개
게시글
질문&답변
2020.08.27
백엔드 https적용후 로그인시 cors에러
네 껐다가 다시 시작해봤습니다 ㅠㅠ
- 0
- 3
- 234
질문&답변
2020.08.12
팔로워,팔로잉 더보기 버튼시 3명씩 더불러오기가 수행되지 않습니다.
요청은 잘 보내집니다. preview나 response탭에는 처음 3개 이후로는 담겨있지 않네요 ㅠㅠ
- 0
- 3
- 185
질문&답변
2020.07.31
sequelize 이용하여 mysql연결 이 안됩니다.
그렇네요 저 부분을 빼먹어서 belongsTo등 함수가 선언이 안되어있다고 떴네요 ㄷㄷ 그런데, index.js 의 NODE_ENV 환경변수와 , app.js의 db.sequelize.sync()가 여전히 선언되지 않았다고 뜨네요 ㅠㅠ 50%진행률 부분의 시퀄라이즈 + nodemon 부분 따라하고 있습니다! 실행은 잘 됩니다
- 0
- 6
- 123
질문&답변
2020.07.31
sequelize 이용하여 mysql연결 이 안됩니다.
index.js const Sequelize = require ( 'sequelize' ); const env = process . env . NODE_ENV || 'development' ; const config = require ( '../config/config.json' )[ env ]; const db = {}; const sequelize = new Sequelize ( config . database , config . username , config . password , config ); db . Comment = require ( './comment' ); db . Hashtag = require ( './hashtag' ); db . Image = require ( './image' ); db . Post = require ( './post' ); db . User = require ( './user' ); Object . keys ( db ). forEach ( modelName => { if ( db [ modelName ]. associate ) { db [ modelName ]. associate ( db ); } }); db . sequelize = sequelize ; db . Sequelize = Sequelize ; module . exports = db ; app.js const express = require ( 'express' ); const postRouter = require ( './routes/post' ); const db = require ( './models' ); const app = express (); db . sequelize . sync () . then (() => { console . log ( "db 연결 성공 " ); }) . catch ( console . error ); app . get ( '/' , ( req , res ) => { res . send ( 'hello express' ); }); app . get ( '/api' , ( req , res ) => { res . send ( 'hello api' ); }); app . get ( '/posts' , ( req , res ) => { res . json ([ { id : 1 , content : 'hello1' }, { id : 2 , content : 'hello2' }, { id : 3 , content : 'hello3' }, ]); }); app . use ( '/post' , postRouter ); app . listen ( 3065 , () => { console . log ( ' 서버 실행중 ' ); }); post.js module . exports = ( sequelize , DataTypes ) => { const Post = sequelize . define ( 'Post' , { content : { type : DataTypes . TEXT , allowNull : false , }, }, { charset : 'utf8mb4' , collate : 'utf8mb4_general_ci' , }); Post . associate = ( db ) => { db . Post . belongsTo ( db . User ); db . Post . belongsTo ( db . Comment ); db . Post . belongsToMany ( db . Hashtag ,{ through : 'PostHashtag' }); db . Post . belongsTo ( db . Image ); db . Post . belongsTo ( db . Post , { as : 'Reetweet' }); db . Post . belongsToMany ( db . User , { through : 'Like' , as : 'Likers' }); }; return Post ; };
- 0
- 6
- 123