build admin-wrapper

master
sajjad 4 months ago
commit c2bc067e34

23
.gitignore vendored

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
package-lock.json
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -0,0 +1,109 @@
const url = require('url'),
fs = require('fs');
var express = require('express');
var serveStatic = require('serve-static');
app = express();
app.use(serveStatic(__dirname + "/dist"));
var port = process.env.PORT || 8082;
var hostname = '127.0.0.1';
fs.readdir('./node_modules/@we', (err, modules) => {
if (err)
return console.log(err);
modules.forEach(module => {
app.get(`/${module}/js/*`, (req, res, next) => {
const pathName = url.parse(req.url).pathname;
if (pathName.startsWith(`/${module}/js/`)) {
fs.readFile(`./node_modules/@we/${module}/dist/${module}/js/` + pathName.replace(`/${module}/js/`, ''), function (err, data) {
try {
if (data) {
res.writeHead(200);
res.write(data);
return res.end();
}
} catch {
}
});
};
});
app.get(`/${module}/css/*`, (req, res, next) => {
const pathName = url.parse(req.url).pathname;
if (pathName.startsWith(`/${module}/css/`)) {
fs.readFile(`./node_modules/@we/${module}/dist/${module}/css/` + pathName.replace(`/${module}/css/`, ''), function (err, data) {
try {
if (data) {
res.writeHead(200);
res.write(data);
return res.end();
}
} catch {
}
});
};
});
app.get(`/${module}/img/*`, (req, res, next) => {
const pathName = url.parse(req.url).pathname;
if (pathName.startsWith(`/${module}/img/`)) {
fs.readFile(`./node_modules/@we/${module}/dist/${module}/img/` + pathName.replace(`/${module}/img/`, ''), function (err, data) {
try {
if (data) {
res.writeHead(200);
res.write(data);
return res.end();
}
} catch {
}
});
}
});
app.get(`/service-worker.js`, (req, res, next) => {
const pathName = url.parse(req.url).pathname;
fs.readFile(`./node_modules/@we/${module}/dist/service-worker.js`, function (err, data) {
try {
if (data) {
res.writeHead(200);
res.write(data);
return res.end();
}
} catch {
}
});
})
app.get(`/${module}/*`, (req, res, next) => {
fs.readFile(`./node_modules/@we/${module}/dist/index.html`, function (err, data) {
try {
if (data) {
res.writeHead(200);
res.write(data);
return res.end();
}
} catch {
}
});
});
app.get(`/${module}`, (req, res, next) => {
return res.redirect(`/${module}/home`);
});
});
});
app.listen(port, hostname, (err) => {
if (err) console.log("Error in server setup")
console.log(`Server running at http://${hostname}:${port}/`);
});

@ -0,0 +1,32 @@
{
"name": "@we/admin-wrapper",
"version": "0.0.1",
"description": "router management",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@we/global": "../global",
"@we/common": "../common",
"@we/crm": "../crm",
"@we/main": "../main",
"@we/user": "../user",
"@we/notification": "../notification",
"@we/blog": "../blog",
"@we/portfolio": "../portfolio",
"@we/store": "../store",
"@we/product": "../product",
"@we/app-management": "../app-management",
"@we/site-management": "../site-management",
"@we/finance": "../finance",
"@we/roll-call": "../roll-call",
"@we/service": "../service",
"@we/service-store": "../service-store",
"@we/warehouse": "../warehouse",
"@we/lms": "../lms",
"express": "^4.18.2"
},
"author": "saji_kk",
"license": "ISC"
}
Loading…
Cancel
Save