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