1seok2

catch all for same route, add sample codes

/**
* @author : wonseog
* @date : 2021/03/08
* @description : 메인 app
* index.ts에서 pathname 받아
* 컴포넌트 제작 후 반환
**/
import Header from "./views/header/Header";
import Body from "./views/body/Body";
import Footer from "./views/footer/Footer";
const App = (pathname : string) : string => {
let contents : string = `
<div>
${Header()}
hello ${pathname}
${Body()}
${Footer()}
</div>
`;
return contents;
}
export default App;
\ No newline at end of file
export const Bye = () => console.log('Bye!');
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 타이틀 대 / 중 / 소 반환
**/
const titleTemplate = (type : string, title : string) => `
<div class="${type}-title">
${type} ${title}
</div>
`
const Title = (title : string) => ({
Large : titleTemplate('large', title),
Medium : titleTemplate('medium', title),
Small : titleTemplate('small', title)
})
export default Title;
\ No newline at end of file
......@@ -6,7 +6,7 @@
<title>home</title>
</head>
<body>
<div id="App"> </div>
<div id="App"></div>
<!-- <script src="public/main.js" ></script>-->
</body>
</html>
\ No newline at end of file
......
import {Bye} from './Bye';
import './assets/style/App.css';
import v4 from './assets/image/v4Logo.png';
const hi = 'hchoi won';
const hi1 = () => {
console.log(hi);
Bye();
const tag = window.document.querySelector('#App');
if(tag) {
tag.innerHTML = `<img src=${v4} alt="image" />`;
}
};
hi1();
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 현재 pathname을 파악 후 App으로 전달
**/
import App from "./App";
window.addEventListener('DOMContentLoaded', () => {
const $App = document.querySelector('#App');
let pathname = window.location.pathname.split('/')[1];
$App && ($App.innerHTML = App(pathname));
})
\ No newline at end of file
......
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 내용
**/
const Body = () : string => {
return `
<div class="Body">Its my Body</div>
`;
}
export default Body;
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 푸터
**/
const Footer = () : string => {
return `
<div class="Footer">Its my Footer</div>
`;
}
export default Footer;
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 헤더
**/
import Title from "../../components/title";
const Header = () : string => {
return `
<div class="header">${Title('im title').Large}</div>
`;
}
export default Header;
\ No newline at end of file
......@@ -5,6 +5,7 @@ from crawler.crawler_instagram import crawler_instagram
my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public'
app = Flask(__name__, static_folder=os.path.abspath(my_path))
def update(insta_id):
crawler_instagram(insta_id)
......@@ -18,24 +19,18 @@ def update(insta_id):
def page_not_found():
return render_template('404.html')
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def home(path):
print("hi? your in '%s' !!"%(path))
# if path != "" and os.path.exists(app.static_folder + '/' + path):
# return send_from_directory(app.static_folder, path)
# else:
# return send_from_directory(app.static_folder, 'index.html')
if path == 'update':
insta_id = request.args.get('insta_id')
update(insta_id)
elif path == '' :
# elif path == '':
else:
root_dir = os.path.dirname(os.getcwd())
return send_from_directory(os.path.join(root_dir, 'check-your-instagram', 'app', 'public'), filename='index.html')
return render_template('index.html')
# else:
# return render_template('index.html')
if __name__ == "__main__":
print("-" * 60)
......