mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: import path and dev server using tsc and nodemon
This commit is contained in:
1 parent
ea33434bea
commit
48dbac7907
16 files changed
+34
-28
No files matched your search
@@ -0,0 +1,2 @@
|
||||
ADMIN_USERNAME=alex
|
||||
ADMIN_PASSWORD=Alex1234
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"watch": ["src"],
|
||||
"watch": ["dist", "views"],
|
||||
"ext": "ts,handlebars,js",
|
||||
"ignore": ["src/**/*.spec.ts"],
|
||||
"exec": "node --loader ts-node/esm src/index.ts"
|
||||
"exec": "node -r source-map-support/register dist/index.js",
|
||||
"delay": 200
|
||||
}
|
||||
@@ -6,13 +6,14 @@
|
||||
"type": "module",
|
||||
"license": "GPL",
|
||||
"scripts": {
|
||||
"start": "node --loader ts-node/esm src/index.ts",
|
||||
"start": "node dist/index.js",
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w",
|
||||
"dev": "nodemon --loader ts-node/esm src/index.ts"
|
||||
"dev": "concurrently \"yarn watch\" \"nodemon\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@linux-odyssey/models": "*",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.18.2",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
"express-handlebars": "^7.1.2",
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
dotenv.config({ path: '.env.dev' })
|
||||
}
|
||||
|
||||
function getOrFailed(key: string): string {
|
||||
if (!process.env[key]) {
|
||||
throw new Error(`Missing required environment variable: ${key}`)
|
||||
@@ -16,13 +22,13 @@ interface Config {
|
||||
|
||||
const config: Config = {
|
||||
host: process.env.HOST || 'localhost',
|
||||
port: process.env.PORT ? parseInt(process.env.PORT) : 3001,
|
||||
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 3001,
|
||||
db: process.env.MONGO_URL || 'mongodb://localhost:27017/odyssey-test',
|
||||
username: getOrFailed('ADMIN_USERNAME'),
|
||||
password: getOrFailed('ADMIN_PASSWORD'),
|
||||
baseUrl:
|
||||
process.env.BASE_URL ||
|
||||
`http://${process.env.HOST || 'localhost'}:${process.env.PORT ? parseInt(process.env.PORT) : 3001}`,
|
||||
`http://${process.env.HOST || 'localhost'}:${process.env.PORT ? parseInt(process.env.PORT, 10) : 3001}`,
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
import Pagination from '../models/pagination.ts'
|
||||
import Pagination from '../models/pagination.js'
|
||||
import { errorCommands } from '../models/commands.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { userCount } from '../models/users.js'
|
||||
import { questList } from '../models/quests.ts'
|
||||
import { questList } from '../models/quests.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function homeController(req: any, res: any) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { questList } from '../models/quests.ts'
|
||||
import { questList } from '../models/quests.js'
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function questListController(req: any, res: any) {
|
||||
const quests = await questList()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Pagination from '../models/pagination.ts'
|
||||
import { sessionList, sessionDetail } from '../models/sessions.ts'
|
||||
import { Request, Response } from 'express'
|
||||
import type { Request, Response } from 'express'
|
||||
import Pagination from '../models/pagination.js'
|
||||
import { sessionList, sessionDetail } from '../models/sessions.js'
|
||||
|
||||
export async function sessionListController(req: any, res: any) {
|
||||
const { nextKey, order } = req.query
|
||||
const itemsPerPage = 50
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Pagination from '../models/pagination.ts'
|
||||
import Pagination from '../models/pagination.js'
|
||||
import { userList } from '../models/users.js'
|
||||
|
||||
export async function userListController(req: any, res: any) {
|
||||
|
||||
@@ -2,8 +2,8 @@ import connectDB from '@linux-odyssey/models'
|
||||
import express from 'express'
|
||||
import { engine } from 'express-handlebars'
|
||||
import basicAuth from 'express-basic-auth'
|
||||
import config from './config.ts'
|
||||
import router from './router.ts'
|
||||
import config from './config.js'
|
||||
import router from './router.js'
|
||||
|
||||
async function main() {
|
||||
await connectDB(config.db)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '@linux-odyssey/models'
|
||||
import Pagination from './pagination.ts'
|
||||
import Pagination from './pagination.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function errorCommands(pagination: Pagination) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Command, Session } from '@linux-odyssey/models'
|
||||
import Pagination from './pagination.ts'
|
||||
import { Types } from 'mongoose'
|
||||
import Pagination from './pagination.js'
|
||||
|
||||
function formatTime(time: number) {
|
||||
const seconds = Math.floor(time / 1000)
|
||||
@@ -44,7 +44,6 @@ export async function sessionList(pagination: Pagination): Promise<any[]> {
|
||||
commands,
|
||||
lastActivityAt,
|
||||
} = session
|
||||
console.log(finishedAt)
|
||||
return {
|
||||
_id,
|
||||
user: user.username, // Assuming `user` is always populated.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Session, User } from '@linux-odyssey/models'
|
||||
import Pagination from './pagination.ts'
|
||||
import Pagination from './pagination.js'
|
||||
|
||||
function loginMethods(user: any) {
|
||||
const methods = []
|
||||
|
||||
@@ -2,12 +2,12 @@ import { Router } from 'express'
|
||||
|
||||
import { homeController } from './controllers/index.js'
|
||||
import { userListController } from './controllers/users.js'
|
||||
import { questListController } from './controllers/quests.ts'
|
||||
import { commandListController } from './controllers/commands.ts'
|
||||
import { questListController } from './controllers/quests.js'
|
||||
import { commandListController } from './controllers/commands.js'
|
||||
import {
|
||||
sessionDetailController,
|
||||
sessionListController,
|
||||
} from './controllers/sessions.ts'
|
||||
} from './controllers/sessions.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"rootDir": "src",
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"noEmit": true,
|
||||
"allowImportingTsExtensions": true
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
|
||||
@@ -2791,7 +2791,7 @@ dompurify@^3.0.6:
|
||||
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.0.9.tgz#b3f362f24b99f53498c75d43ecbd784b0b3ad65e"
|
||||
integrity sha512-uyb4NDIvQ3hRn6NiC+SIFaP4mJ/MdXlvtunaqK9Bn6dD3RuB/1S/gasEjDHD8eiaqdSael2vBv+hOs7Y+jhYOQ==
|
||||
|
||||
dotenv@*, dotenv@^16.3.1, dotenv@^16.4.1:
|
||||
dotenv@*, dotenv@^16.3.1, dotenv@^16.4.1, dotenv@^16.4.5:
|
||||
version "16.4.5"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
|
||||
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==
|
||||
|
||||
Reference in new issue
Block a user