examples to new tsrpc-cli
This commit is contained in:
@@ -4,23 +4,23 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"test": "mocha test/**/*.test.ts",
|
||||
"build": "tsrpc build"
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^15.12.5",
|
||||
"mocha": "^9.0.1",
|
||||
"@types/mocha": "^8.2.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"mocha": "^9.1.2",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.4"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
@@ -14,13 +14,14 @@ server.flows.preRecvBufferFlow.push(async v => {
|
||||
let conn = v.conn as HttpConnection;
|
||||
|
||||
if (conn.httpReq.method === 'GET') {
|
||||
conn.logger.log('[GET]', conn.httpReq.url);
|
||||
// Static File Service
|
||||
if (conn.httpReq.url) {
|
||||
// Check whether the file is existed
|
||||
// Check if the file is existed
|
||||
let resFilePath = path.join('res', conn.httpReq.url)
|
||||
let isExisted = await fs.access(resFilePath).then(() => true).catch(() => false);
|
||||
if (isExisted) {
|
||||
// Response the file
|
||||
if (isExisted && (await fs.stat(resFilePath)).isFile()) {
|
||||
// Send the file
|
||||
let content = await fs.readFile(resFilePath);
|
||||
conn.httpRes.end(content);
|
||||
return undefined;
|
||||
|
36
examples/custom-http-res/tsrpc.config.ts
Normal file
36
examples/custom-http-res/tsrpc.config.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
// {
|
||||
// from: 'src/shared',
|
||||
// to: '../frontend/src/shared',
|
||||
// type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
// }
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
Reference in New Issue
Block a user