Massive refactor to get rid of the global app.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import * as http from 'http'
|
||||
import * as url from 'url'
|
||||
import api from './api'
|
||||
import { Notice } from 'obsidian'
|
||||
import { getSettings } from 'src/settings'
|
||||
import type OmnisearchPlugin from '../main'
|
||||
import { getApi } from './api'
|
||||
|
||||
export function getServer() {
|
||||
export function getServer(plugin: OmnisearchPlugin) {
|
||||
const api = getApi(plugin)
|
||||
const server = http.createServer(async function (req, res) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||
res.setHeader(
|
||||
@@ -47,7 +48,7 @@ export function getServer() {
|
||||
},
|
||||
() => {
|
||||
console.log(`Omnisearch - Started HTTP server on port ${port}`)
|
||||
if (getSettings().httpApiNotice) {
|
||||
if (plugin.settings.httpApiNotice) {
|
||||
new Notice(`Omnisearch - Started HTTP server on port ${port}`)
|
||||
}
|
||||
}
|
||||
@@ -62,9 +63,8 @@ export function getServer() {
|
||||
},
|
||||
close() {
|
||||
server.close()
|
||||
const settings = getSettings()
|
||||
console.log(`Omnisearch - Terminated HTTP server`)
|
||||
if (settings.httpApiEnabled && settings.httpApiNotice) {
|
||||
if (plugin.settings.httpApiEnabled && plugin.settings.httpApiNotice) {
|
||||
new Notice(`Omnisearch - Terminated HTTP server`)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user