-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,846 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Fastify MVC sample | ||
|
||
Note that if you are running the Nest app on a remote machine, you may need to change the listen address, as per [these instructions](https://docs.nestjs.com/techniques/performance#adapter): | ||
|
||
`await app.listen(3000, '0.0.0.0')` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"compilerOptions": { | ||
"builder": "swc", | ||
"typeCheck": true | ||
}, | ||
"sourceRoot": "src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["src"], | ||
"ext": "ts", | ||
"ignore": ["src/**/*.spec.ts"], | ||
"exec": "ts-node ./src/main" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@repo/server", | ||
"version": "1.0.0", | ||
"description": "Roxy Browser 开放 API", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"dev": "pnpm start:dev", | ||
"build": "nest build --builder webpack", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/main", | ||
"lint": "eslint '{src,apps,libs,test}/**/*.ts' --fix", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", | ||
"test:e2e": "echo 'No e2e tests implemented yet.'" | ||
}, | ||
"dependencies": { | ||
"@fastify/static": "7.0.4", | ||
"@fastify/view": "9.1.0", | ||
"@nestjs/common": "10.4.1", | ||
"@nestjs/core": "10.4.1", | ||
"@nestjs/platform-fastify": "10.4.1", | ||
"class-transformer": "^0.5.1", | ||
"class-validator": "^0.14.1", | ||
"handlebars": "4.7.8", | ||
"reflect-metadata": "0.2.2", | ||
"rimraf": "6.0.1", | ||
"rxjs": "7.8.1" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "10.4.4", | ||
"@nestjs/schematics": "10.1.4", | ||
"@nestjs/testing": "10.4.1", | ||
"@swc/cli": "^0.4.0", | ||
"@types/express": "4.17.21", | ||
"@types/node": "22.4.1", | ||
"@types/supertest": "6.0.2", | ||
"jest": "29.7.0", | ||
"supertest": "6.3.3", | ||
"swc-loader": "^0.2.6", | ||
"ts-jest": "29.1.2", | ||
"ts-loader": "9.5.1", | ||
"ts-node": "10.9.2", | ||
"tsconfig-paths": "4.2.0", | ||
"tsconfig-paths-webpack-plugin": "^4.1.0", | ||
"typescript": "5.5.4", | ||
"webpack": "^5.94.0", | ||
"webpack-cli": "^5.1.4" | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Controller, Get, Render } from '@nestjs/common' | ||
|
||
@Controller() | ||
export class AppController { | ||
@Get() | ||
@Render('index.hbs') | ||
root() { | ||
return { message: 'Hello world!' } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common' | ||
import { AppController } from './app.controller' | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { join } from 'node:path' | ||
import { NestFactory } from '@nestjs/core' | ||
import handlebars from 'handlebars' | ||
import type { NestFastifyApplication } from '@nestjs/platform-fastify' | ||
import { FastifyAdapter } from '@nestjs/platform-fastify' | ||
import { AppModule } from './app.module' | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create<NestFastifyApplication>( | ||
AppModule, | ||
new FastifyAdapter(), | ||
) | ||
app.useStaticAssets({ | ||
root: join(__dirname, '..', 'public'), | ||
prefix: '/public/', | ||
}) | ||
app.setViewEngine({ | ||
engine: { | ||
handlebars, | ||
}, | ||
templates: join(__dirname, '..', 'views'), | ||
}) | ||
|
||
await app.listen(3000) | ||
console.log(`Application is running on: ${await app.getUrl()}`) | ||
} | ||
bootstrap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"incremental": true, | ||
"target": "ES2021", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"baseUrl": "./", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"removeComments": true, | ||
"sourceMap": true, | ||
"allowSyntheticDefaultImports": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>App</title> | ||
</head> | ||
|
||
<body> | ||
{{ message }} | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const path = require('node:path') | ||
const { IgnorePlugin } = require('webpack') | ||
const { | ||
swcDefaultsFactory, | ||
} = require('@nestjs/cli/lib/compiler/defaults/swc-defaults') | ||
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin') | ||
|
||
/** @type { import('webpack').Configuration } */ | ||
module.exports = { | ||
entry: './src/main', | ||
externals: {}, | ||
module: { | ||
rules: [ | ||
{ | ||
exclude: /node_modules/, | ||
test: /\.ts$/, | ||
use: { | ||
loader: 'swc-loader', | ||
options: swcDefaultsFactory().swcOptions, | ||
}, | ||
}, | ||
], | ||
}, | ||
node: { | ||
__dirname: false, | ||
__filename: false, | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: path.resolve(__dirname, 'dist/'), | ||
}, | ||
plugins: [ | ||
new IgnorePlugin({ | ||
checkResource(resource) { | ||
const lazyImports = [ | ||
'@fastify/static', | ||
'@fastify/view', | ||
'@nestjs/microservices', | ||
'@nestjs/microservices/microservices-module', | ||
'@nestjs/platform-express', | ||
'@nestjs/websockets/socket-module', | ||
'amqp-connection-manager', | ||
'amqplib', | ||
'cache-manager', | ||
'cache-manager/package.json', | ||
'class-transformer/storage', | ||
'hbs', | ||
'ioredis', | ||
'kafkajs', | ||
'mqtt', | ||
'nats', | ||
] | ||
if (!lazyImports.includes(resource)) { | ||
return false | ||
} | ||
try { | ||
require.resolve(resource, { paths: [process.cwd()] }) | ||
} | ||
catch (err) { | ||
// console.log(err) | ||
return Boolean(err) | ||
} | ||
return false | ||
}, | ||
}), | ||
], | ||
resolve: { | ||
extensions: ['.js', '.json', '.ts'], | ||
mainFields: ['main'], | ||
plugins: [new TsconfigPathsPlugin({ configFile: 'tsconfig.json' })], | ||
}, | ||
target: 'node', | ||
} |
Oops, something went wrong.