File tree 7 files changed +34
-11
lines changed
7 files changed +34
-11
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "overrides": [
5
+ {
6
+ "files": ["**/.*rc", "**/*.json"],
7
+ "options": { "parser": "json" }
8
+ }
9
+ ]
10
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ transport : "http" , // ws | http
3
+ apiPort : 8001 ,
4
+ staticPort : 8000 ,
5
+ staticPath : "./static" ,
6
+ logPath : "./log" ,
7
+ db : {
8
+ host : "127.0.0.1" ,
9
+ port : 5432 ,
10
+ database : "example" ,
11
+ user : "marcus" ,
12
+ password : "marcus" ,
13
+ } ,
14
+ } ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const pg = require ( 'pg' ) ;
4
+ const config = require ( './config.js' ) ;
4
5
5
- const pool = new pg . Pool ( {
6
- host : '127.0.0.1' ,
7
- port : 5432 ,
8
- database : 'example' ,
9
- user : 'marcus' ,
10
- password : 'marcus' ,
11
- } ) ;
6
+ const pool = new pg . Pool ( config . db ) ;
12
7
13
8
module . exports = ( table ) => ( {
14
9
async query ( sql , args ) {
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const http = require ( 'node:http' ) ;
4
+ const console = require ( './logger.js' ) ;
4
5
5
6
const receiveArgs = async ( req ) => {
6
7
const buffers = [ ] ;
Original file line number Diff line number Diff line change 3
3
const fs = require ( 'node:fs' ) ;
4
4
const util = require ( 'node:util' ) ;
5
5
const path = require ( 'node:path' ) ;
6
+ const config = require ( './config.js' ) ;
6
7
7
8
const COLORS = {
8
9
info : '\x1b[1;37m' ,
@@ -68,4 +69,4 @@ class Logger {
68
69
}
69
70
}
70
71
71
- module . exports = new Logger ( './log' ) ;
72
+ module . exports = new Logger ( config . logPath ) ;
Original file line number Diff line number Diff line change 2
2
3
3
const fsp = require ( 'node:fs' ) . promises ;
4
4
const path = require ( 'node:path' ) ;
5
- const server = require ( './ws.js' ) ;
6
5
const staticServer = require ( './static.js' ) ;
7
6
const load = require ( './load.js' ) ;
8
7
const db = require ( './db.js' ) ;
9
8
const hash = require ( './hash.js' ) ;
10
9
const logger = require ( './logger.js' ) ;
10
+ const config = require ( './config.js' ) ;
11
+ const server = require ( `./${ config . transport } .js` ) ;
11
12
12
13
const sandbox = {
13
14
console : Object . freeze ( logger ) ,
@@ -26,6 +27,6 @@ const routing = {};
26
27
routing [ serviceName ] = await load ( filePath , sandbox ) ;
27
28
}
28
29
29
- staticServer ( './static' , 8000 ) ;
30
- server ( routing , 8001 ) ;
30
+ staticServer ( config . staticPath , config . staticPort ) ;
31
+ server ( routing , config . apiPort ) ;
31
32
} ) ( ) ;
Original file line number Diff line number Diff line change 3
3
const http = require ( 'node:http' ) ;
4
4
const path = require ( 'node:path' ) ;
5
5
const fs = require ( 'node:fs' ) ;
6
+ const console = require ( './logger.js' ) ;
6
7
7
8
module . exports = ( root , port ) => {
8
9
http . createServer ( async ( req , res ) => {
You can’t perform that action at this time.
0 commit comments