mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Made a bunch of changes to the source code. And polish the deploying
process.
This commit is contained in:
parent
1200505451
commit
fc7b835d68
5 changed files with 72 additions and 20 deletions
|
@ -1,18 +1,21 @@
|
||||||
services:
|
services:
|
||||||
newsanalyze-service:
|
newsanalyze-service:
|
||||||
image: ghcr.io/hpware/news-analyze:latest
|
image: ghcr.io/hpware/news-analyze:master
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
|
||||||
interval: 1m
|
interval: 1m
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- web
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.newsanalyze.rule=Host(`news.yuanhau.com`)"
|
- "traefik.http.routers.newsanalyze.rule=Host(`news.yuanhau.com`)"
|
||||||
- "traefik.http.routers.newsanalyze.entrypoints=webinternal"
|
- "traefik.http.routers.newsanalyze.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.newsanalyze.tls=true"
|
||||||
|
- "traefik.http.routers.newsanalyze.tls.certresolver=myresolver"
|
||||||
- "traefik.http.services.newsanalyze.loadbalancer.server.port=3000"
|
- "traefik.http.services.newsanalyze.loadbalancer.server.port=3000"
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
web:
|
web:
|
||||||
|
|
7
server/api/health.ts
Normal file
7
server/api/health.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default defineEventHandler(async () => {
|
||||||
|
return {
|
||||||
|
status: "healthy",
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
version: process.env.npm_package_version || "unknown",
|
||||||
|
};
|
||||||
|
});
|
3
server/api/search/news.ts
Normal file
3
server/api/search/news.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
return {};
|
||||||
|
});
|
|
@ -1,5 +1,5 @@
|
||||||
// This should be hooked up to a database soon.
|
// This should be hooked up to a database soon.
|
||||||
import postgres from "~/server/components/postgres";
|
import sql from "~/server/components/postgres";
|
||||||
|
|
||||||
// Parse Date Function
|
// Parse Date Function
|
||||||
function checkDate(dateString: string) {
|
function checkDate(dateString: string) {
|
||||||
|
@ -40,8 +40,25 @@ export default defineEventHandler(async (event) => {
|
||||||
path: "/",
|
path: "/",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!loginCookie) {
|
||||||
|
setCookie(event, "lastCheckCookie", nowDate, {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
path: "/",
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
auth: false,
|
||||||
|
user: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const loginCookieStore = atob(loginCookie);
|
||||||
|
/*const findUser = sql`
|
||||||
|
select * from userlogintokens
|
||||||
|
where token = ${loginCookieStore}
|
||||||
|
`;*/
|
||||||
return {
|
return {
|
||||||
auth: true,
|
auth: true,
|
||||||
user: "testing",
|
user: "testing",
|
||||||
|
loginCookie: loginCookieStore, // Debug
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,34 +1,56 @@
|
||||||
import sql from "~/server/components/postgres";
|
import sql from "~/server/components/postgres";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import argon2 from "argon2";
|
import argon2 from "argon2";
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const salt = process.env.PASSWORD_HASH_SALT;
|
const salt = process.env.PASSWORD_HASH_SALT;
|
||||||
if (!salt) {
|
if (!salt) {
|
||||||
throw createError({
|
return {
|
||||||
statusCode: 500,
|
error: "SALT_NOT_FOUND",
|
||||||
message: "Internal server error",
|
};
|
||||||
});
|
|
||||||
}
|
}
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
const { username, password } = body;
|
const { username, password } = body;
|
||||||
if (!username || !password) {
|
if (!username || !password) {
|
||||||
throw createError({
|
return {
|
||||||
statusCode: 400,
|
error: "NO_USER_AND_PASSWORD_SUBMITED",
|
||||||
message: "Username and password are required",
|
};
|
||||||
});
|
|
||||||
}
|
}
|
||||||
const USERNAME_PATTERN = /^[a-zA-Z0-9_]{3,20}$/;
|
const USERNAME_PATTERN = /^[a-zA-Z0-9_]{3,20}$/;
|
||||||
if (!USERNAME_PATTERN.test(username)) {
|
if (!USERNAME_PATTERN.test(username)) {
|
||||||
throw createError({
|
return {
|
||||||
statusCode: 400,
|
error: "INVALD_USER_ACCOUNT",
|
||||||
message: "Invalid username.",
|
};
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Server side hashing
|
// Server side hashing
|
||||||
const hashedPassword = await argon2.hash(salt, password);
|
const hashedPassword = await argon2.hash(salt, password);
|
||||||
|
|
||||||
// Check if user exists, if not, create a user
|
// Check if user exists, if not, create a user
|
||||||
try {
|
try {
|
||||||
console.log(username);
|
const fetchUserInfo = await sql`
|
||||||
console.log(hashedPassword);
|
select * from users
|
||||||
} catch (e) {}
|
where user = ${username}`;
|
||||||
|
if (!fetchUserInfo) {
|
||||||
|
/*const createNewUser = await sql`
|
||||||
|
insert
|
||||||
|
`*/
|
||||||
|
// INSERT USER CREATING STUFF HERE LATER
|
||||||
|
} else {
|
||||||
|
if (fetchUserInfo.password !== hashedPassword) {
|
||||||
|
return {
|
||||||
|
error: "PASSWORD_NO_MATCH",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const newToken = uuidv4();
|
||||||
|
const newToken64 = atob(newToken);
|
||||||
|
const saveNewToken = await sql``;
|
||||||
|
return {
|
||||||
|
user: fetchUserInfo.user,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
error: "UNABLE_TO_PROCESS",
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue