Started switching to CommonJS
import to require
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import * as config from "./config/index.js";
|
||||
const config = require("./config/index.js");
|
||||
const { port, dbPass, cookiesSecret } = config;
|
||||
import express from "express";
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
import loaders from "./loaders/index.js";
|
||||
const loaders = require("./loaders/index.js");
|
||||
//
|
||||
// Server init function
|
||||
//
|
||||
@@ -1,15 +1,15 @@
|
||||
import dotenv from "dotenv";
|
||||
const dotenv = require("dotenv");
|
||||
dotenv.config();
|
||||
|
||||
export const port = process.env.PORT;
|
||||
export const dbPass = process.env.DB_PASS;
|
||||
export const dbUser = process.env.DB_USER;
|
||||
export const dbHost = process.env.DB_HOST;
|
||||
export const dbPort = process.env.DB_PORT;
|
||||
export const dbName = process.env.DB_NAME;
|
||||
export const cookiesSecret = process.env.COOKIES_SECRET;
|
||||
export const jwtSecret = process.env.JWT_SECRET;
|
||||
export const CRM_KEY = process.env.CRM_KEY;
|
||||
export const CRM_USER = process.env.CRM_USER;
|
||||
export const CRM_EMAIL = process.env.CRM_EMAIL;
|
||||
export const MAIL_PASS = process.env.MAIL_PASS;
|
||||
exports.port = process.env.PORT;
|
||||
exports.dbPass = process.env.DB_PASS;
|
||||
exports.dbUser = process.env.DB_USER;
|
||||
exports.dbHost = process.env.DB_HOST;
|
||||
exports.dbPort = process.env.DB_PORT;
|
||||
exports.dbName = process.env.DB_NAME;
|
||||
exports.cookiesSecret = process.env.COOKIES_SECRET;
|
||||
exports.jwtSecret = process.env.JWT_SECRET;
|
||||
exports.CRM_KEY = process.env.CRM_KEY;
|
||||
exports.CRM_USER = process.env.CRM_USER;
|
||||
exports.CRM_EMAIL = process.env.CRM_EMAIL;
|
||||
exports.MAIL_PASS = process.env.MAIL_PASS;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import bodyParser from "body-parser";
|
||||
import cors from "cors";
|
||||
import rateLimiter from "express-rate-limit";
|
||||
import helmet from "helmet";
|
||||
import routeDish from "../routes/routeDish.js";
|
||||
import routeRestaurant from "../routes/routeRestaurant.js";
|
||||
import routeUser from "../routes/routeUser.js";
|
||||
import routeSearch from "../routes/routeSearch.js";
|
||||
import routeImg from "../routes/routeImg.js";
|
||||
import routePayments from "../routes/routePayments.js";
|
||||
const bodyParser = require("body-parser");
|
||||
const cors = require("cors");
|
||||
const rateLimiter = require("express-rate-limit");
|
||||
const helmet = require("helmet");
|
||||
const routeDish = require("../routes/routeDish.js");
|
||||
const routeRestaurant = require("../routes/routeRestaurant.js");
|
||||
const routeUser = require("../routes/routeUser.js");
|
||||
const routeSearch = require("../routes/routeSearch.js");
|
||||
const routeImg = require("../routes/routeImg.js");
|
||||
const routePayments = require("../routes/routePayments.js");
|
||||
|
||||
export default ({ app, secret }) => {
|
||||
const loadExpress = ({ app, secret }) => {
|
||||
const limiter = rateLimiter({
|
||||
windowMs: 15 * 60 * 1000, //time window
|
||||
max: 100, //requests from a single IP for a time window
|
||||
max: 100, //requests = a single IP for a time window
|
||||
});
|
||||
|
||||
app.use(cors({ exposedHeaders: "x-auth-token" }));
|
||||
@@ -32,3 +32,5 @@ export default ({ app, secret }) => {
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
module.exports = loadExpress;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import expressLoader from "./express.js";
|
||||
import mongooseLoader from "./mongoose.js";
|
||||
const expressLoader = require("./express.js");
|
||||
const mongooseLoader = require("./mongoose.js");
|
||||
|
||||
export default async ({ expressApp, secret }) => {
|
||||
const loaders = async ({ expressApp, secret }) => {
|
||||
const mongoConnection = await mongooseLoader();
|
||||
console.log("Mongoose Loaded");
|
||||
await expressLoader({ app: expressApp, secret: secret });
|
||||
console.log("Express Initialized");
|
||||
};
|
||||
|
||||
module.exports = loaders;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import mongoose from "mongoose";
|
||||
import { dbPass, dbUser, dbHost, dbPort, dbName } from "../config/index.js";
|
||||
const mongoose = require("mongoose");
|
||||
const {
|
||||
dbPass,
|
||||
dbUser,
|
||||
dbHost,
|
||||
dbPort,
|
||||
dbName,
|
||||
} = require("../config/index.js");
|
||||
|
||||
export default async () => {
|
||||
const loadMongoose = async () => {
|
||||
const connection = await mongoose.connect(
|
||||
"mongodb://" +
|
||||
dbHost +
|
||||
@@ -25,3 +31,5 @@ export default async () => {
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = loadMongoose;
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
"name": "menui_backend",
|
||||
"version": "1.0.0",
|
||||
"description": "backend for Menui",
|
||||
"main": "app.mjs",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"keywords": [],
|
||||
"type": "module",
|
||||
"author": "Jonasz Bigda",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
||||
59
web.config
59
web.config
@@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This configuration file is required if iisnode is used to run node processes behind
|
||||
IIS or IIS Express. For more information, visit:
|
||||
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
|
||||
<webSocket enabled="false" />
|
||||
<handlers>
|
||||
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
|
||||
<add name="iisnode" path="app.mjs" verb="*" modules="iisnode"/>
|
||||
</handlers>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<!-- Do not interfere with requests for node-inspector debugging -->
|
||||
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
|
||||
<match url="^app.mjs\/debug[\/]?" />
|
||||
</rule>
|
||||
|
||||
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
|
||||
<rule name="StaticContent">
|
||||
<action type="Rewrite" url="public{REQUEST_URI}"/>
|
||||
</rule>
|
||||
|
||||
<!-- All other URLs are mapped to the node.js site entry point -->
|
||||
<rule name="DynamicContent">
|
||||
<conditions>
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
|
||||
</conditions>
|
||||
<action type="Rewrite" url="server.js"/>
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
|
||||
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
|
||||
<security>
|
||||
<requestFiltering>
|
||||
<hiddenSegments>
|
||||
<remove segment="bin"/>
|
||||
</hiddenSegments>
|
||||
</requestFiltering>
|
||||
</security>
|
||||
|
||||
<!-- Make sure error responses are left untouched -->
|
||||
<httpErrors existingResponse="PassThrough" />
|
||||
|
||||
<!--
|
||||
You can control how Node is hosted within IIS using the following options:
|
||||
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
|
||||
* node_env: will be propagated to node as NODE_ENV environment variable
|
||||
* debuggingEnabled - controls whether the built-in debugger is enabled
|
||||
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
|
||||
-->
|
||||
<!--<iisnode watchedFiles="web.config;*.js"/>-->
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user