Commit a749747f authored by Lee Soobeom's avatar Lee Soobeom
Browse files

/api/posts route

parent 58a76189
......@@ -29,6 +29,7 @@
"webpack-dev-server": "^4.9.2"
},
"dependencies": {
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0"
......
import React, { useState, MouseEvent, MouseEventHandler } from "react";
import React, { MouseEventHandler } from "react";
import { PostType } from "./typesrc";
type Props = {
......
export interface PostType {
id: string;
title: string;
body?:string;
date: string;
counts: number;
counts?: number;
theme?: string;
city?: string;
}
\ No newline at end of file
......@@ -6,5 +6,13 @@ const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
devServer: {historyApiFallback: true },
devServer: {
proxy:[
{
context: ["/api"],
target:"http://localhost:3000",
changOrigin: true,
},
],
historyApiFallback: true },
});
......@@ -33,6 +33,7 @@
"typescript": "^4.7.4"
},
"dependencies": {
"axios": "^0.27.2",
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.6",
"express": "^4.18.1",
......
export * as userCtrl from "./user.controller";
export * as authCtrl from "./auth.controller";
export * as postCtrl from "./post.controller";
\ No newline at end of file
import { NextFunction, Request, Response } from "express";
import { asyncWrap } from "../helpers";
import jwt, { JwtPayload } from "jsonwebtoken";
import { jwtCofig, envConfig, cookieConfig } from "../config";
import { postDb } from "../db";
export const posting = asyncWrap(async (req, res) => {
const { title, body, date, theme, city } = req.body;
// 1) title 빈 문자열인지 확인
const titleString = postDb.checkTitleNull(title, );
if (!titleString) {
return res.status(422).send(`${title} 제목을 입력해 주세요`);
}
// 2) body 빈 문자열인지 확인
const bodyString = postDb.checkBodyNull(body, );
if (!bodyString) {
return res.status(422).send(`${body} 여행 후기를 입력해 주세요`);
}
// 3) submit 이벤트 발생시 date값 입력
const dateGet = postDb.getSubmitDate(date, );
// 4) theme dropdown default-value일 경우 에러
const themeSelect = postDb.selectTheme(theme, );
if (!themeSelect) {
return res.status(422).send(`${theme} 테마를 선택해 주세요`)
}
// 5) cuty dropdown default-value일 경우 에러
const citySelect = postDb.selectCity(city, );
if (!citySelect) {
return res.status(422).send(`${city} 도시를 선택해 주세요`)
}
// 6) 토큰 생성
const token = jwt.sign({ }, jwtCofig.secret, {
expiresIn: jwtCofig.expires,
});
// 7) 쿠키에 토큰 저장
res.cookie(cookieConfig.name, token, {
maxAge: cookieConfig.maxAge,
path: "/",
httpOnly: envConfig.mode === "production",
secure: envConfig.mode === "production",
});
// 8) 사용자 반환
res.json({});
});
\ No newline at end of file
export * as userDb from "./user.db";
export * as postDb from "./post.db";
export const checkTitleNull = async (
title : string,
) => {
}
export const checkBodyNull = async (
body : string,
) => {
}
export const getSubmitDate = async (
date : string,
) => {
}
export const selectTheme = async (
theme : string,
) => {
let user;
if( theme != "테마" ) {
}
}
export const selectCity = async (
city : string,
) => {
let user;
if ( city != "도시" ) {
}
}
import express from "express";
import userRouter from "./user.route";
import authRouter from "./auth.route";
import postRouter from "./post.route";
const router = express.Router();
router.use("/users", userRouter);
router.use("/auth", authRouter);
router.use("/posts", postRouter);
export default router;
import express from "express";
import { postCtrl } from "../controllers";
const router = express.Router();
router.route("/posting").post(postCtrl.posting);
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment