All: Remove dev.mjs and just have single file index.mjs that detects if it is being run directly.

This commit is contained in:
Jonatan Nilsson 2023-11-05 04:50:11 +00:00
parent 7f4dce5920
commit ddb66d9836
9 changed files with 85 additions and 74 deletions

View file

@ -1,24 +0,0 @@
import fs from 'fs'
import { ServiceCore } from 'service-core'
import * as index from './index.mjs'
const port = 4120
var core = new ServiceCore('nfp_moe', import.meta.url, port, '')
let config = {
frontend: {
url: 'http://localhost:' + port
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = port
core.setConfig(config)
core.init(index).then(function() {
return core.run()
})

View file

@ -1,3 +1,5 @@
import fs from 'fs'
import { pathToFileURL } from 'url'
import config from './base/config.mjs'
export function start(http, port, ctx) {
@ -9,3 +11,28 @@ export function start(http, port, ctx) {
return server.run()
})
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
import('service-core').then(core => {
const port = 4120
var core = new core.ServiceCore('nfp_moe', import.meta.url, port, '')
let config = {
frontend: {
url: 'http://localhost:' + port
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = port
core.setConfig(config)
core.init({ start }).then(function() {
return core.run()
})
})
}

View file

@ -8,8 +8,8 @@
"test": "test"
},
"scripts": {
"start": "node --experimental-modules index.mjs",
"dev:server": "node dev.mjs | bunyan",
"start": "node index.mjs",
"dev:server": "node index.mjs | bunyan",
"dev": "npm-watch dev:server"
},
"watch": {

View file

@ -1,22 +0,0 @@
import fs from 'fs'
import { ServiceCore } from 'service-core'
import * as index from './index.mjs'
var core = new ServiceCore('nfp_moe', import.meta.url, 4030, '')
let config = {
frontend: {
url: 'http://localhost:4030'
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = 4030
core.setConfig(config)
core.init(index).then(function() {
return core.run()
})

View file

@ -1,3 +1,5 @@
import fs from 'fs'
import { pathToFileURL } from 'url'
import config from './base/config.mjs'
export function start(http, port, ctx) {
@ -9,3 +11,28 @@ export function start(http, port, ctx) {
return server.run()
})
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
import('service-core').then(core => {
const port = 4030
var core = new core.ServiceCore('nfp_moe', import.meta.url, port, '')
let config = {
frontend: {
url: 'http://localhost:' + port
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = port
core.setConfig(config)
core.init({ start }).then(function() {
return core.run()
})
})
}

View file

@ -13,7 +13,7 @@
"build:prod": "asbundle app/index.js public/assets/app.js && asbundle app/admin/admin.js public/assets/admin.js",
"build": "asbundle app/index.js public/assets/app.js && asbundle app/admin/admin.js public/assets/admin.js",
"dev:build": "npm-watch build",
"dev:server": "node dev.mjs | bunyan",
"dev:server": "node index.mjs | bunyan",
"dev": "npm-watch dev:server",
"watch:sass:public": "sass --watch app/app.scss public/assets/app.css",
"watch:sass:admin": "sass --watch app/admin.scss public/assets/admin.css",

View file

@ -1,24 +0,0 @@
import fs from 'fs'
import { ServiceCore } from 'service-core'
import * as index from './index.mjs'
const port = 4120
var core = new ServiceCore('nfp_moe', import.meta.url, port, '')
let config = {
frontend: {
url: 'http://localhost:' + port
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = port
core.setConfig(config)
core.init(index).then(function() {
return core.run()
})

View file

@ -1,3 +1,5 @@
import fs from 'fs'
import { pathToFileURL } from 'url'
import config from './api/config.mjs'
export function start(http, port, ctx) {
@ -9,3 +11,28 @@ export function start(http, port, ctx) {
return server.run()
})
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
import('service-core').then(core => {
const port = 4120
var core = new core.ServiceCore('saproxy', import.meta.url, port, '')
let config = {
frontend: {
url: 'http://localhost:' + port
}
}
try {
config = JSON.parse(fs.readFileSync('./config.json'))
} catch {}
config.port = port
core.setConfig(config)
core.init({ start }).then(function() {
return core.run()
})
})
}

View file

@ -9,7 +9,7 @@
},
"scripts": {
"start": "node --experimental-modules index.mjs",
"dev:server": "node dev.mjs | bunyan",
"dev:server": "node index.mjs | bunyan",
"dev": "npm-watch dev:server"
},
"watch": {