-
Notifications
You must be signed in to change notification settings - Fork 22
Read app path from applications file #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,25 +1,38 @@ | ||||||||||||||||||
| 'use strict'; | ||||||||||||||||||
|
|
||||||||||||||||||
| const fastify = require('fastify'); | ||||||||||||||||||
| const { resolve } = require('node:path'); | ||||||||||||||||||
| const { readFile } = require('node:fs/promises'); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to have compound identifiers like |
||||||||||||||||||
|
|
||||||||||||||||||
| const path = require('node:path'); | ||||||||||||||||||
| const fastify = require('fastify'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const { Logger, StreamForLogger } = require('./src/logger.js'); | ||||||||||||||||||
| const http = require('./src/http.js'); | ||||||||||||||||||
| const ws = require('./src/ws.js'); | ||||||||||||||||||
| const { loadApplication } = require('./src/loader.js'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const APPLICATION_PATH = path.join(process.cwd(), '../NodeJS-Application'); | ||||||||||||||||||
| const APPLICATIONS_FILE_PATH = '.applications'; | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need no constant, string content is easy to understand |
||||||||||||||||||
| const LOG_FOLDER_PATH = './log'; | ||||||||||||||||||
|
|
||||||||||||||||||
| const getAppPaths = async (appFilePath) => { | ||||||||||||||||||
| const appsFile = await readFile(resolve(appFilePath), { | ||||||||||||||||||
| encoding: 'utf8', | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| return appsFile.split('\n').filter((path) => path.trim() !== ''); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| (async () => { | ||||||||||||||||||
| const streamForLogger = new StreamForLogger(LOG_FOLDER_PATH); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| const server = fastify({ logger: { level: 'info', stream: streamForLogger } }); | ||||||||||||||||||
| const server = fastify({ | ||||||||||||||||||
| logger: { level: 'info', stream: streamForLogger }, | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+26
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| const logger = new Logger(server.log); | ||||||||||||||||||
| const app = await loadApplication(APPLICATION_PATH, logger); | ||||||||||||||||||
|
|
||||||||||||||||||
| const appPath = (await getAppPaths(APPLICATIONS_FILE_PATH))[0]; | ||||||||||||||||||
| const app = await loadApplication(appPath, logger); | ||||||||||||||||||
|
|
||||||||||||||||||
| http.init(server, app.api); | ||||||||||||||||||
| http.initStatic(server, APPLICATION_PATH); | ||||||||||||||||||
| http.initStatic(server, appPath); | ||||||||||||||||||
| ws.init(server, app.api); | ||||||||||||||||||
| http.start(server, { port: app.config.server.ports[0] }); | ||||||||||||||||||
| })(); | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.