serve public files
This commit is contained in:
parent
f8466fb261
commit
6716937735
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(req.params.id);
|
const id = parseInt(req.params.id);
|
||||||
const userId = 1; // hardcoded for now, use userId from token
|
const deletedPost = await deletePost(id, req.userId);
|
||||||
const deletedPost = await deletePost(id, userId);
|
|
||||||
if (deletedPost instanceof Error) {
|
if (deletedPost instanceof Error) {
|
||||||
return res.status(403).send(deletedPost.message);
|
return res.status(403).send(deletedPost.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { Request, Response } from 'express';
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
req.body.id = parseInt(req.params.id);
|
req.body.id = parseInt(req.params.id);
|
||||||
req.body.authorId = 1; // hardcoded for now, use userId from token
|
req.body.authorId = req.userId;
|
||||||
const post: Post = Post.parse(req.body);
|
const post: Post = Post.parse(req.body);
|
||||||
const editedPost: PrismaPost | null | Error = await editPost(post);
|
const editedPost: PrismaPost | null | Error = await editPost(post);
|
||||||
if (editedPost === null) {
|
if (editedPost === null) {
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const id = parseInt(req.params.id);
|
const id = parseInt(req.params.id);
|
||||||
const userId = 1; // hardcoded for now, use userId from token
|
const likedPost = await likePost(id, req.userId);
|
||||||
const likedPost = await likePost(id, userId);
|
|
||||||
if (likedPost instanceof Error) {
|
if (likedPost instanceof Error) {
|
||||||
return res.status(403).send(likedPost.message);
|
return res.status(403).send(likedPost.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Request, Response } from 'express';
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
req.body.authorId = 1; // hardcoded for now, use userId from token
|
req.body.authorId = req.userId;
|
||||||
const post: Post = Post.parse(req.body);
|
const post: Post = Post.parse(req.body);
|
||||||
const newPost: PrismaPost = await createPost(post);
|
const newPost: PrismaPost = await createPost(post);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const postId = parseInt(req.params.id);
|
const postId = parseInt(req.params.id);
|
||||||
const userId = 1; // hardcoded for now, use userId from token
|
const likedPost = await unlikePost(postId, req.userId);
|
||||||
const likedPost = await unlikePost(postId, userId);
|
|
||||||
if (likedPost instanceof Error) {
|
if (likedPost instanceof Error) {
|
||||||
return res.status(403).send(likedPost.message);
|
return res.status(403).send(likedPost.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import api from '@/api';
|
||||||
import { config as envConfig } from 'dotenv';
|
import { config as envConfig } from 'dotenv';
|
||||||
import { deleteExpiredTokens } from '@/controller/AuthController';
|
import { deleteExpiredTokens } from '@/controller/AuthController';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
envConfig();
|
envConfig();
|
||||||
|
|
||||||
|
|
@ -40,6 +41,8 @@ app.use(cors());
|
||||||
app.use(json({ limit: '50mb' }));
|
app.use(json({ limit: '50mb' }));
|
||||||
app.use(urlencoded({ extended: true, limit: '50mb' }));
|
app.use(urlencoded({ extended: true, limit: '50mb' }));
|
||||||
|
|
||||||
|
app.use(express.static(path.join(__dirname, '../public')));
|
||||||
|
|
||||||
app.use('/api', api);
|
app.use('/api', api);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ export {};
|
||||||
declare global {
|
declare global {
|
||||||
namespace Express {
|
namespace Express {
|
||||||
export interface Request {
|
export interface Request {
|
||||||
userId?: number;
|
userId: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue