add options param in serve func for the keys recursive and recreate
This commit is contained in:
parent
960e73f467
commit
4179b66de7
1 changed files with 32 additions and 1 deletions
|
@ -3,6 +3,8 @@ import Defaults from '../entities/Defaults.js';
|
||||||
import Client from '../dao/client.js';
|
import Client from '../dao/client.js';
|
||||||
import Server from '../dao/socketServer.js';
|
import Server from '../dao/socketServer.js';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
|
import { mkdirParentsPathSync } from "../helpers/mkdirp.js";
|
||||||
|
import fileUnlink from '../helpers/fileUnlink.js';
|
||||||
|
|
||||||
class IPC{
|
class IPC{
|
||||||
constructor(){
|
constructor(){
|
||||||
|
@ -97,7 +99,7 @@ function disconnect(id){
|
||||||
delete this.of[id];
|
delete this.of[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
function serve(path,callback){
|
function serve(path,callback, options={}){
|
||||||
if(typeof path=='function'){
|
if(typeof path=='function'){
|
||||||
callback=path;
|
callback=path;
|
||||||
path=false;
|
path=false;
|
||||||
|
@ -115,6 +117,35 @@ function serve(path,callback){
|
||||||
callback=emptyCallback;
|
callback=emptyCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
recursive,
|
||||||
|
recreate
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
if (recreate) {
|
||||||
|
try {
|
||||||
|
fileUnlink(path);
|
||||||
|
} catch (e){
|
||||||
|
this.log(
|
||||||
|
'Error deleting socket file',
|
||||||
|
path,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recursive) {
|
||||||
|
try {
|
||||||
|
mkdirParentsPathSync(path);
|
||||||
|
} catch (e) {
|
||||||
|
this.log(
|
||||||
|
'Error creating socket directory',
|
||||||
|
path,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.server=new Server(
|
this.server=new Server(
|
||||||
path,
|
path,
|
||||||
this.config,
|
this.config,
|
||||||
|
|
Loading…
Add table
Reference in a new issue